如何将一个数组分成N个等分的数组
1个回答
展开全部
把Java中的集合,数组,字符串整合成一个统一的api。很类似JQuery中的著名的$函数。
看例子吧:
// 产生 0, 1, 2, 3, 4序列
List list = $(5).toList();
// 指定开始结束的序列 10, 11, 12, 13, 14
List list2 = $(10, 15).toList();
// 产生随机数序列
List randomIntegers = $(new Random(), 100).samples(50).sort().toList();
// jion方法,我太喜欢了。"4->3->2->1->0"
$(5).reverse().join("->");
// join() any iterable to a String
$(array).join();
$(list).join();
$(set).join();
// join() works also for 'range' type
$(5, 10).join(); // "56789"
$('a', 'd').join("-"); // "a-b-c-d"
// and even on strings, StringBuilders, etc
$("aaa").join(" "); // "a a a"
// repeat Strings, but it works also for any Iterable/Collection and
Array
String repeat = $("abc").repeat(3).join(" "); // "abc abc abc"
// convert Long[] to long[], while sorting it
Long[] aLongArray = { 42L, 84L };
long[] longs = $(aLongArray).sort().toLongArray();
// fluent interface: convert a primitive int array to ArrayList, in the
reversed order
int[] array = { 4, 2, -5 };
List list = $(array).sort().reverse().toList();
// you can even unbox a short[] array to long[] (since it doesn't cause a
loss of precision)
short[] shorts = { 42, 42, 42 };
long[] $(shorts).toLongArray();
// syntactic sugar
$("a string").size(); // "a string".length()
$(aCollection).size(); // aCollection.size()
$(anArray).size(); // anArray.length
$(array).toString(); // calls Arrays.toString()
// for loop以前这么写
for (int i = 0; i < 10; i++) {
}
// 现在只需要
for (int i : $(10)) {
}
//查找 排序 取出最大最小值
$(any).indexOf(T)
$(any).sort(Comparator)
$(any).max(Comparator)
$(any).min(Comparator)
看例子吧:
// 产生 0, 1, 2, 3, 4序列
List list = $(5).toList();
// 指定开始结束的序列 10, 11, 12, 13, 14
List list2 = $(10, 15).toList();
// 产生随机数序列
List randomIntegers = $(new Random(), 100).samples(50).sort().toList();
// jion方法,我太喜欢了。"4->3->2->1->0"
$(5).reverse().join("->");
// join() any iterable to a String
$(array).join();
$(list).join();
$(set).join();
// join() works also for 'range' type
$(5, 10).join(); // "56789"
$('a', 'd').join("-"); // "a-b-c-d"
// and even on strings, StringBuilders, etc
$("aaa").join(" "); // "a a a"
// repeat Strings, but it works also for any Iterable/Collection and
Array
String repeat = $("abc").repeat(3).join(" "); // "abc abc abc"
// convert Long[] to long[], while sorting it
Long[] aLongArray = { 42L, 84L };
long[] longs = $(aLongArray).sort().toLongArray();
// fluent interface: convert a primitive int array to ArrayList, in the
reversed order
int[] array = { 4, 2, -5 };
List list = $(array).sort().reverse().toList();
// you can even unbox a short[] array to long[] (since it doesn't cause a
loss of precision)
short[] shorts = { 42, 42, 42 };
long[] $(shorts).toLongArray();
// syntactic sugar
$("a string").size(); // "a string".length()
$(aCollection).size(); // aCollection.size()
$(anArray).size(); // anArray.length
$(array).toString(); // calls Arrays.toString()
// for loop以前这么写
for (int i = 0; i < 10; i++) {
}
// 现在只需要
for (int i : $(10)) {
}
//查找 排序 取出最大最小值
$(any).indexOf(T)
$(any).sort(Comparator)
$(any).max(Comparator)
$(any).min(Comparator)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询