class="java">List<String>l1 = new ArrayList<String>(); List<String>l2 = new LinkedList<String>(); add(int index, Object obj); set(int index, Object obj); public static void main(String[]args){ String a = "A", b = "B", c = "C", d = "D", e = "E"; List<String> list = new LinkedList<String>(); list.add(a); list.add(e); list.add(d); list.set(1, b);//将索引位置为1的对象e修改为对象b list.add(2, c);//将对象c添加到索引位置为2的位置 Iterator<String> it = list.Iterator(); while(it.hasnext()){ System.out.println(it.next()); } } for (int i = 0; i < list.size(); i++ ) { System.out.println(list.get(i)); } import java.util.ArrayList; import java.util.LinkedList; import java.util.Iterator; import java.util.List; public class TestCollection{ public static void main(String[]args){ System.out.println("开始:"); String a = "A", b = "B", c = "C", d = "D", e = "E"; List<String> list = new LinkedList<String>(); list.add(a); list.add(e); list.add(d); list.set(1, b); list.add(2, c); Iterator<String> it = list.iterator(); while(it.hasnext()){ System.out.println(it.next()); } for (int i = 0; i < list.size() ; i++) { System.out.println(list.get(i)); } System.out.println("结束!"); } } public static void main(String[]args){ String a = "A", b = "B", c = "C", d = "D",repeat = "Repeat"; List<String>list = new LinkedList<String>(); list.add(a); list.add(repeat); list.add(b); list.add(repeat); list.add(c); list.add(repeat); list.add(d); System.out.println(list.indexOf(repeat)); System.out.println(list.lastIndexOf(repeat)); System.out.println(list.indexOf(b)); System.out.println(list.lastIndexOf(b)); System.out.println("结束!"); } public static void main(String[]args){ String a = "A", b = "B", c = "C", d ="D", e = "E"; List<String> list = new ArrayList<String>(); list.add(a); list.add(b); list.add(c); list.add(d); list.add(e); list = list.subList(1, 3);//利用从索引位置1到3的对象重新生成一个List集合 for (int i = 0; i < lst.size() ;i++ ) { System.out.println(list.get(i)); } } List list = new LinkedList(); list = new ArrayList(); list.add(0, "b"); list.add(list.size(), "any"); b = list.remove("b"); b = list.remove(0); String[] strArray = new String[]{"z","a","C"}; List list = Arrays.asList(strArray); Collections.sort(list); Collections.sort(list,String.CASE_INSENSITIVE_ORDER); Collections.sort(list,Collections.reverseOrder()); Collections.sort(list, String.CASE_INSENSITIVE_ORDER); Collections.reverse(list); list1.retainAll(list2); list1.subList(newSize,list1.size()); list.add(); Array.asList(); Collections.sort(); Collections.reverseOrder(); Collections.reverse(); list.addAll(); list.retainAll(); list.subList(size1,size2);
?