1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package list;
import java.util.ArrayList; import java.util.List; @SuppressWarnings("all") public class ListMethod { public static void main(String[] args) { List list = new ArrayList(); list.add("张三丰"); list.add("贾宝玉"); list.add(1,"亦晓白"); System.out.println(list); System.out.println(list.get(2)); List list2 = new ArrayList(); list2.add("jack"); list2.add("亦晓白"); list2.add("marry"); list.addAll(1,list2); System.out.println(list); System.out.println(list.indexOf("亦晓白")); System.out.println(list.lastIndexOf("亦晓白")); System.out.println(list.remove(1)); System.out.println(list); list.remove("亦晓白"); System.out.println(list); list.set(1,"替换"); System.out.println(list); List retList = list.subList(1,3); System.out.println(retList); } }
|