Arrays工具类十大常用方法
来源:互联网 发布:手机购物软件大全 编辑:程序博客网 时间:2024/05/21 12:47
翻译人员: 铁锚
翻译日期: 2013年11月19日
原文链接: Top 10 Methods for Java Arrays
以下是由 stackoverflow 网站 投票决出的Java数组最常用的十个方法,
0. 声明数组
- String[] aArray = new String[5];
- String[] bArray = {"a","b","c", "d", "e"};
- String[] cArray = new String[]{"a","b","c","d","e"};
- int[] intArray = { 1, 2, 3, 4, 5 };
- String intArrayString = Arrays.toString(intArray);
- // 直接打印,则会打印出引用对象的Hash值
- // [I@7150bd4d
- System.out.println(intArray);
- // [1, 2, 3, 4, 5]
- System.out.println(intArrayString);
- String[] stringArray = { "a", "b", "c", "d", "e" };
- ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray));
- // [a, b, c, d, e]
- System.out.println(arrayList);
- String[] stringArray = { "a", "b", "c", "d", "e" };
- boolean b = Arrays.asList(stringArray).contains("a");
- // true
- System.out.println(b);
- int[] intArray = { 1, 2, 3, 4, 5 };
- int[] intArray2 = { 6, 7, 8, 9, 10 };
- // Apache Commons Lang 库
- int[] combinedIntArray = ArrayUtils.addAll(intArray, intArray2);
- method(new String[]{"a", "b", "c", "d", "e"});
- // containing the provided list of elements
- // Apache common lang
- String j = StringUtils.join(new String[] { "a", "b", "c" }, ", ");
- // a, b, c
- System.out.println(j);
- String[] stringArray = { "a", "b", "c", "d", "e" };
- ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray));
- String[] stringArr = new String[arrayList.size()];
- arrayList.toArray(stringArr);
- for (String s : stringArr)
- System.out.println(s);
- Set<String> set = new HashSet<String>(Arrays.asList(stringArray));
- //[d, e, b, c, a]
- System.out.println(set);
- int[] intArray = { 1, 2, 3, 4, 5 };
- ArrayUtils.reverse(intArray);
- //[5, 4, 3, 2, 1]
- System.out.println(Arrays.toString(intArray));
- int[] intArray = { 1, 2, 3, 4, 5 };
- int[] removed = ArrayUtils.removeElement(intArray, 3);//创建新的数组
- System.out.println(Arrays.toString(removed));
- byte[] bytes = ByteBuffer.allocate(4).putInt(8).array();
- for (byte t : bytes) {
- System.out.format("0x%x ", t);
- }
0 0
- Arrays工具类十大常用方法
- Arrays工具类十大常用方法
- Arrays工具类十大常用方法
- Arrays工具类十大常用方法
- Arrays工具类十大常用方法
- java Arrays工具类十大常用方法
- Arrays工具类中的常用方法
- 常用的工具类及方法:System、Math、Random、Arrays
- Arrays类常用方法
- Arrays常用方法
- Arrays的常用方法
- Arrays的常用方法
- Arrays的常用方法
- Arrays类常用方法
- Arrays常用方法
- Arrays常用方法源码
- 19-集合框架工具类-17-常用对象API(集合框架-工具类-Arrays-方法介绍)
- 19-集合框架工具类-18-常用对象API(集合框架-工具类-Arrays-asList方法)
- api设计摘要
- PHP为什么会被认为是草根语言?(转)
- Linux中的文件压缩,打包和备份命令
- PHP调用MYSQL存储过程方法
- Java 抽象类与接口总结
- Arrays工具类十大常用方法
- Effective Objective-C 2.0:Item 52: Remember that NSTimer Retains Its Target
- js 学习
- 嵌入式C语言不可不用的关键字
- JSP/Servlet基础——ServletMVC小例子
- win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程
- Datediff函数 助你实现不同进制时间之间的运算
- IOS开发之UINavigationController详解
- SQL注入攻击