赞
踩
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class Teeee ...{
List list = new LinkedList();
public static void main(String[] args) ...{
List list = new LinkedList();
for (int i = 0; i < 9; i++) ...{
list.add("a"+i);
}
Collections.sort(list);//顺序排列
System.out.println(list);
Collections.shuffle(list);//混乱的意思
System.out.println(list);
Collections.reverse(list);//倒序排列
System.out.println(list);
System.out.println(Collections.binarySearch(list, "a5"));//折半查找
或者
for(int i=list.size()-1;i>=0;i--)
{
System.out.println(list.get(i));
}
}
List<String> list = new ArrayList<String>(); list.add("a1"); list.add("a2"); String[] toBeStored = list.toArray(new String[list.size()]); for(String s : toBeStored) { System.out.println(s); }
另外的一个例子:
- ArrayList<Point> a1 = new ArrayList<Point>();
- a1.add(new Point(3, 3));
- a1.add(new Point(4, 4));
- a1.add(new Point(5, 5));
- Object[] objs = a1.toArray(); // 利用ArrayList的toArray()返回一个对象的数组.
- for (int i = 0; i < objs.length; i++)
- {
- System.out.println(objs[i]);
- }
- System.out.println(objs);//
- List<Object> l = Arrays.asList(objs);// Arrays.asList()返回一个列表.
- System.out.println(l);
或
List<String> list = new ArrayList<String>(); list.add("a1"); list.add("a2"); String[] toBeStored = new String[al.size()]; list.toArray(toBeStored); for (String s : toBeStored) { System.out.println(s);
}
或
List<String> list = new ArrayList<String>(); list.add("a1"); list.add("a2"); String[] toBeStored = new String[]{}; String[] str = al.toArray(toBeStored); for (String s : str) { System.out.println(s); }
或
http://hi.baidu.com/liangchaoyjs/blog/item/32aa89c72aaddad4d100609a.html
或者 list.toArray();最简单
附:将数组转换为list列表
public class Test
{
public static void main(String[] args)
{
String[] strs ={"a","b","c","d"};
List<String> list = Arrays.asList(strs);
Collections.shuffle(list);
for(String str:list)
{
System.out.println(str);
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。