ArrayList
package ArrayListT; import java.util.ArrayList; public class ArrayListTest1 { public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<String> arrayList = new ArrayList<String>(); //ArrayList arrayList = new ArrayList(); //共有的方法 arrayList.add("1"); arrayList.add("2"); arrayList.add("4"); arrayList.add("5"); arrayList.add(2, "3"); System.out.println(arrayList);//1,2,3,4,5 int lenght = arrayList.size();//5 System.out.println(lenght);//5 String two = arrayList.get(2);//强制转换 3 System.out.println(two); //3 System.out.println(arrayList.contains("6"));//false arrayList.remove("5");//1,2,3,4 System.out.println(arrayList.size());//4 arrayList.remove(0);//2,3,4 System.out.println(arrayList.contains("1"));//false System.out.println(arrayList.indexOf("2"));//0 System.out.println(arrayList.lastIndexOf("4"));//2 arrayList.set(0, "0");//0,3,4 System.out.println(arrayList.contains("2"));//false System.out.println(arrayList.indexOf("0"));//0 //存对象数据 ArrayList<News> arrayList2 = new ArrayList<News>(); News news0 = new News("1", "12"); News news1 = new News("2", "23"); News news2 = new News("3", "34"); News news3 = new News("4", "45"); arrayList2.add(news0); arrayList2.add(news1); arrayList2.add(news2); arrayList2.add(news3); } } }