List It's an ordered set , So you can see that arrays are also collections , The difference between them is in the length of the array , and List You don't need to .
The definition of set is very simple

ArrayList And vector They're all ordered sets , Allow repetition , In general, the ordered collection is used in the case of multithreading vector, Because it ensures thread safety .
List l=new ArrayList();
ArrayList Provided add\remove And so on
l.add(" Zhang "); l.add(" king "); l.add(" Zhao ");
But if I mix in here and add some int It's also allowed
l.add(" Zhang "); l.add(" king "); l.add(" Zhao "); l.add(3);
But it doesn't make sense , We have to constrain types to make sense
List<String> l=new ArrayList(); l.add(" Zhang "); l.add(" king "); l.add(" Zhao "); l.add(3);
// This will not compile , Because it's already constrained for String;
Ergodic collective method 1( This method is not recommended ):for
for (int i = 0; i <l.size() ; i++) { System.out.println(l.get(i)); }
Ergodic collective method 2( recommend )Iterator
List<String> l=new ArrayList(); l.add(" Zhang "); l.add(" king "); l.add(" Zhao "); for(
Iterator<String> it= l.iterator();it.hasNext();){ System.out.println(;
Ergodic collective method 3( recommend )for each The cycle becomes Iterator Call of
for (String s:l ) { System.out.println(s); }
ArrayList It is generally used in single thread ; and vector It's used the same way , But it's not as efficient as it is , However, thread safety is generally used in multithreading .

©2019-2020 Toolsou All rights reserved,
Final review of database : Summary of comprehensive application questions Laplance operator ( Second derivative ) Simple learning of computer composition principle pyqt Button call python program _PyQt: Link button to function in program How much can you go up once you change jobs ? Today, I saw the ceiling of job hopping python in str Function usage _python in str Usage Summary of built-in functions MySQL trigger web The server nginx---linux Installation and deployment C++ Chapter V polymorphism exercises :( It's coming to an end )python Check built-in functions , How to check python Built in function