Java dollarJava 集合、数组和字符串整合API
把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)