List and ArrayList in java

A, java in the List and ArrayList

List is an interface, there are a lot of implementation classes such as: ArrayList, LinkedList, Vector with which it is new which

ArrayList is an implementation of the List interface inherits and implements the interface List

List a = new ArrayList();

Two, List.add () and List.addAll () method

1, List.addAll: Add the list each element to the current list of

List a = new ArrayList();
a.add(1);
a.add(2);
a.add(3);

List b = new ArrayList();
b.add(4);
b.add(5);
b.add(6);

a.addAll(b);

operation result:

[1,2,3,4,5,6]

2, List.add: the current list as a list of elements added to it

List a = new ArrayList();
a.add(1);
a.add(2);
a.add(3);

List b = new ArrayList();
b.add(4);
b.add(5);
b.add(6);

a.add(b);

operation result:

[1,2,3, [4,5,6] ]

Published 13 original articles · won praise 1 · views 149

Guess you like

Origin blog.csdn.net/weixin_43363236/article/details/103246076