zoukankan      html  css  js  c++  java
  • 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);
        }
        }
    
    }
  • 相关阅读:
    Sigma Function 数学 因子求和
    luogu P3800 Power收集
    LibreOJ #110. 乘法逆元
    luogu P3802 小魔女帕琪
    LibreOJ #6000. 「网络流 24 题」搭配飞行员
    LibreOJ #103. 子串查找
    LibreOJ #102. 最小费用流
    LibreOJ #109. 并查集
    BZOJ 1922: [Sdoi2010]大陆争霸
    LibreOJ #119. 最短路
  • 原文地址:https://www.cnblogs.com/xiaolei121/p/5759103.html
Copyright © 2011-2022 走看看