ArrayList,Vector,LinkedList,泛型(Generic)

ArrayList

  1. Use Arraylist implement storage objects will be deleted calendar and duplicate objects

public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(100);
list.add(100);
list.add(100);
list.add(100);
list.add(100);
list.add(100);
list.add(200);
deleEle(list);
System.out.println(list);
}

private static void deleEle(ArrayList list) {
for (int i = 0; i < list.size(); i++) {
Object obj = list.get(i);
if(list.indexOf(obj)!=list.lastIndexOf(obj)){
list.remove(obj);
deleEle(list);
}
}
}

Vector

  1. Vector Class Overview: Vector class implements a growable array of objects, Vector is synchronized.

  2. Vector class-specific features
    public void the addElement (E obj)
    public E elementAt (int index)
    public the Enumeration Elements ()

LinkedList

  1. LinkedList class overview: List linked list implementation of the interface, this implementation is not synchronized

  2. LinkedList class-specific features
    public void addFirst (E e) and addLast (E E)
    public E getFirst () and getLast ()
    public removeFirst E () and public E removeLast ()

Generics

  1. Generic wildcard <?>: Any type, if not explicitly, then that Object as well as any of the Java class

  2. ? Extends E: downward limit, E and its subclasses

  3. ? Super E: limited upward, E and its parent class

ArrayList objects = new ArrayList();
//?泛型统配符
ArrayList<?> objects2 = new ArrayList();
//向上限定
ArrayList<? super Animal> objects3 = new ArrayList();
//ArrayList<? super Animal> objects4 = new ArrayList();
ArrayList<? super Animal> objects4 = new ArrayList();
//向下限定
ArrayList<? extends Animal> objects5 = new ArrayList();
ArrayList<? extends Animal> objects6= new ArrayList();
ArrayList<? extends Animal> objects7 = new ArrayList();

ArrayList list = new ArrayList<>();
list.add(20);
ArrayList list2 = new ArrayList<>();
list2.add(200);
list.addAll(list2);

  1. If generic data types defined the future, then the requirements of both sides must be the same type of data

  2. Variable parameters Overview: definition of the method when not know how many parameters that define the

Format: Method Name Modifier return type (data type ... variable name) {}

Note:
A: variable here is actually an array
b: if there is a variable parameter method, and there are a number of parameters, then the variable parameters must be the last one

Published 43 original articles · won praise 7 · views 1775

Guess you like

Origin blog.csdn.net/y18791050779/article/details/102939694