标签:
---恢复内容开始---
1,数组的定义
String[] a = new String[5];//定义数组的长度,称为动态定义。
//下面两种是在分配空间的同时还初始化了值
String[] b = new String[]{"a","b","c","d","e"};
String[] c = {"a","b","c","d","e"};
2.数组的输出
String[] array = {"a","b","c","d","e"};
System.out.println(Arrays.toString(array));// [a, b, c, d, e]
3.转换数组为ArrayList
String[] array = {"a","b","c","d","e"};
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(array));
System.out.println(arrayList);//[a, b, c, d, e]
4.检查数组中是否包含某些值
String[] array = {"a","b","c","d","e"};
System.out.println(Arrars,asList(array).contains("c"));//true
5.数组的排序
用到了Arrays.sort()方法,下面是几种用法
1)Arrays.sort(int[] array)//这样是对数组中所有元素按照从小到大的顺序排列
2)Arrays.sort(int[] a, int fromIndex, int toIndex)//这种是对数组从fromIndea到toIndex的位置按照从小到大的顺序排列(下标为toIndex的不参与排序)
3)Arrays.sort(T[] a,Comparator<T> c)//根据制定的比较器的顺序对a数组进行排序
---恢复内容结束---
标签:
原文地址:http://www.cnblogs.com/fengApr/p/4449017.html