ArrayList Vector의 차이점 복습
1959 단어 초심자
import java.util.ArrayList;
import java.util.Vector;
public class ThreadTest1 implements Runnable{
static ArrayList<String> arr = new ArrayList<String>();
static Vector<String> vector = new Vector<String>();
@Override
public void run() {
for(int i=0;i<=100;i++){
arr.add("a"+i);
if(i==50){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// for(int i=0;i<=100;i++){
// vector.add("a"+i);
// if(i==50){
// try {
// Thread.sleep(1);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
}
// ,
public static void main(String[] args){
ThreadTest1 ss = new ThreadTest1();
Thread t1 = new Thread(ss);
Thread t2 = new Thread(ss);
// Thread t3 = new Thread(ss);
t1.start();
t2.start();
// t3.start();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<ThreadTest1.arr.size();i++){
System.out.println("arr"+"["+i+"]: "+ThreadTest1.arr.get(i));// arr
}
// for(int i=0;i<ThreadTest1.vector.size();i++){
// System.out.println("vector"+"["+i+"]: "+ThreadTest1.vector.get(i));
// }
}
}