java集合,ArrayList,LinkedList知识点总结

  1. @Override
    public String toString() {
    return “Person [name=” + name + “, age=” + age + “]”;
    }

    @Override
    public boolean equals(Object obj) {

    Person p = (Person)obj;
    
    return this.name.equals(p.name) && this.age == p.age;
    

    }

  2. Iterator it = list.iterator();
    while (it.hasNext()){
    Person p = it.next();
    System.out.println(p.getName()+”….”+p.getAge());
    //System.out.println(it.next().getName()+”…..”+it.next().getAge());//第二个it.next()指针又向后移动
    }

  3. String arr[] = list.toArray(new String [0]);//
    for (int i = 0; i < arr.length; i++) {
    System.out.println(arr[i]);
    }

  4. private static void demo1() {
    String arr[] = {“11”,”12”,”13”,”14”,”15”};
    List list = Arrays.asList(arr); //数组加进集合
    System.out.println(list);
    }

  5. String arr[] = list.toArray(new String [0]);//
    for (int i = 0; i < arr.length; i++) {
    System.out.println(arr[i]);
    }

  6. public static ArrayList getSingle(ArrayList list){

    ArrayList newlist = new ArrayList();
    Iterator it = list.iterator();
    while (it.hasNext()){
        Object ob = it.next();
        if (!newlist.contains(ob)){
            newlist.add(ob);
        }
    }
    return newlist;
    

    }

  7. ArrayList

你可能感兴趣的:(java集合,ArrayList,LinkedList知识点总结)