primitive 数组克隆及反转排序
long[] array = { 1, 3, 2, 3, 5, 6
};
long[] reversed = ArrayUtils.clone( array );
ArrayUtils.reverse(
reversed );
System.out.println( "Original: " + ArrayUtils.toString( array )
); //打印
System.out.println( "Reversed: " + ArrayUtils.toString( reversed
) );
对象数组克隆及反转排序
Long[] array = new Long[] { new Long(3), new Long(56), new Long(233) };
Long[] reversed = ArrayUtils.clone( array );
ArrayUtils.reverse( reversed
);
primitive
数组与对象数组之间的转换
long[] primitiveArray = new long[] { 12, 100, 2929,
3323 };
Long[] objectArray = ArrayUtils.toObject( primitiveArray );
Double[] doubleObjects = new Double[] { new Double( 3.22, 5.222, 3.221 ) };
double[] doublePrimitives = ArrayUtils.toPrimitive( doubleObject );
注意:对象数组可以含有null元素,primitive 数组则不容许含有null元素,所以对象数组转换为primitive
数组时,可以添入第二个参数,当碰到为null的元素时用其代替(如下,Double.NaN)。如果不添入第二个参数,当碰到为null的元素时,则会抛出NullPointerException
。
double[] result = ArrayUtils.toPrimitive( resultObjArray, Double.NaN
);
查找一个数组中是否含有特定的元素(查找对象数组时,比较的是对象的equals()方法),及特定元素的第一次出现位置和最后一次出现位置
String[] stringArray = { "Red", "Orange", "Blue", "Brown", "Red" };
boolean
containsBlue = ArrayUtils.contains( stringArray, "Blue" );
int indexOfRed =
ArrayUtils.indexOf( stringArray, "Red");
int lastIndexOfRed =
ArrayUtils.lastIndexOf( string, "Red"
);
由二维对象数组创建一个
Map
Object[] weightArray =
new Object[][] {
{"H" , new Double( 1.007)},
{"He", new Double(
4.002)},
{"Li", new Double(
6.941)},
{"Be", new Double(
9.012)},
{"B", new
Double(10.811)},
{"C", new
Double(12.010)},
{"N", new
Double(14.007)},
{"O", new
Double(15.999)},
{"F", new
Double(18.998)},
{"Ne", new Double(20.180)} };
Map weights = ArrayUtils.toMap( weightArray );
Double hydrogenWeight =
(Double)weights.get( "H" );
注意:当二维对象数组"key"值重复时,创建的Map,后面的键-值对会把前面的覆盖掉
相关推荐
介绍了Apache Jakarta Commons 项目下Java组件,如FileUpload, HttpClient, DBCP,BeanUtils,Logging,Lang, 以及 Collections,Codec等,是学习和使用Apache Jakarta Commons良好的参考使用手册。
jakarta commons cookbook 电子版很实用
jakarta-commons 相关依赖包,文件列表: commons-attributes-api.jar commons-attributes-compiler.jar commons-beanutils.jar commons-codec.jar commons-collections.jar commons-dbcp.jar commons-digester.jar ...
Jakarta Commons组件之commons-lang-2.3-src.zip
Jakarta Commons Online Bookshelf.Mar.2005
jakarta commons-logging 1.1.1
Jakarta Commons Cookbook
本书是一本介绍apache commons使用的电子书
Jakarta Commons使用,方便自己看看的东西。。
Jakarta Commons-lang API & Source Code Jakarta lang包API帮助文档,并带有源码
jakarta commons的API
Jakarta Commons FileUpload 用户指南
commons-discovery 提供工具来定位资源 (包括类) ,通过使用各种模式来映射服务/引用名称和资源名称。 commons-el 提供在JSP2.0规范中定义的EL表达式的解释器. commons-email 提供一组用于发送Email的API,它基于...
jakarta commons cookbook java开发的工具字典。相当实用。
博文链接:https://dcriori.iteye.com/blog/127788
jakarta_commons_io jakarta_commons_io
COMMONS的介绍,关于基本信息和某些类的使用方法
了解Apacche的Jakarta Commons库
NULL 博文链接:https://cmyx2008love.iteye.com/blog/1520235
This book takes the most stable, popular and useful sub-projects that form Jakarta Commons and provides much needed documentation and usage information on how best to incorporate them into Java ...