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,
vue Changes in data Interface not updated Python realization js And Django Front and back interaction in the background JavaSwing To achieve a simple Lianliankan games C# Making a simplified version of calculator elementui Shuttle box el-transfer Display list content text too long JVM summary Regression of dependent variable order categories (R language )【C#】 The realization of student achievement information management system use css Design a simple style html login interface C language --------- Tetris ( source code )