将列表分成批次的常用工具[已关闭](Is there a common Java utility to break a list into batches?)
我自己写了一个工具来将列表分成给定大小的批次。 我只是想知道是否已经有任何apache commons util这个。
public static <T> List<List<T>> getBatches(List<T> collection,int batchSize){ int i = 0; List<List<T>> batches = new ArrayList<List<T>>(); while(i<collection.size()){ int nextInc = Math.min(collection.size()-i,batchSize); List<T> batch = collection.subList(i,i+nextInc); batches.add(batch); i = i + nextInc; } return batches; }
请让我知道,如果有任何现有的工具已经是相同的。
I wrote myself a utility to break a list into batches of given size. I just wanted to know if there is already any apache commons util for this.
public static <T> List<List<T>> getBatches(List<T> collection,int batchSize){ int i = 0; List<List<T>> batches = new ArrayList<List<T>>(); while(i<collection.size()){ int nextInc = Math.min(collection.size()-i,batchSize); List<T> batch = collection.subList(i,i+nextInc); batches.add(batch); i = i + nextInc; } return batches; }
Please let me know if there any existing utility already for the same.
原文:https://stackoverflow.com/questions/12026885
更新时间:2023-11-13 06:11
最满意答案
父母的功能做你想要的:
$(this).parents("tr:first");
The parents function does what you want:
$(this).parents("tr:first");
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你在找这个: $('#a_branch').closest('.forest'); You're looking for this: $('#a_branch').closest('.forest');
-
父母的功能做你想要的: $(this).parents("tr:first"); The parents function does what you want: $(this).parents("tr:first");
-
因为parents()返回从最接近外部元素排序的祖先元素,所以可以链接到eq() : $('#element').parents().eq(0); // "Father". $('#element').parents().eq(2); // "Great-grandfather". Since parents() returns the ancestor elements ordered from the closest to the outer ones, you can chain it into ...
-
很简单: $('#myUl').on('click', 'a', do stuff!); Very simple: $('#myUl').on('click', 'a', do stuff!);
-
通过onclick="tbodyExpand.call(this)"你可以使用: $(this).closest('table').find('tbody'); 否则,函数内部将指向全局对象(窗口)而不是单击的元素。 您可以使用选择器绑定事件,而不是编写内联处理程序。 例: EXPAND CSS: .floatRight{ float: right; } 和 $(function(){ ...
-
:parent不是你想要的。 也许:has()是你所寻找的最接近的伪选择器。 用法: $(html).find('*:has(.model)').text(); 或者更具体地说: $(html).find('h1:has(.model)').text(); :parent is not what you're looking for. Perhaps :has() is the closest pseudo selector to what you're looking for. Usage: $(ht ...
-
正确的解决方案(即实际使用jQuery 选择器而不是jQuery API的解决方案)是这样的: $(':has(> #myElement)'); 这意味着你的“当前元素”实际上必须是'has'参数而不是基表达式。 它不应该改变任何东西,除了它的可读性比< 。 作为参考,在少数情况下,jQuery API可能不是选择器的有效替代品,例如: $(document).on('click', ':has(> .widget)', function () { // ... }); 在这种情况下,选择器允许 ...
-
在这里你去... http://jsfiddle.net/bYaRx/ 我可能在实施方面有点过分了。 我在工作上很无聊。 这是获取正确的img标记的相关jQuery: var $img = $('.X img'); $img.filter(':eq('+($img .length - (n+1))+')'); Here you go... http://jsfiddle.net/bYaRx/ I might have gone a little overboard with the implementat ...