package test;
import java.util.ArrayList;
public class Test1 {
public static void main(String[] args) {
ArrayList arr1 = new ArrayList();
arr1.add(1);
arr1.add("이");
arr1.add(3.5);
for(int i = 0;i<arr1.size();i++) {
Object str = arr1.get(i);
System.out.println(str);
}
ArrayList<String> arr2 = new ArrayList<String>();
arr2.add("일");
arr2.add("이");
arr2.add("삼");
String str2 = arr2.get(1);
for(String s2 : arr2) {
System.out.println(s2);
}
ArrayList<String> arr3 = new ArrayList<>();
}
}
package test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
public class Test2 {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
Vector <String> vector =new Vector<>();
List<String> list2 = new Vector<>();
vector.add("일");
vector.add("이");
vector.add("삼");
System.out.println(vector.get(0));
System.out.println(vector.get(1));
System.out.println(vector.get(2));
LinkedList<String> myList = new LinkedList<>();
myList.add("A");
myList.add("B");
myList.add("C");
System.out.println(myList);
myList.add(1,"D");
System.out.println(myList);
Iterator<String> ir = vector.iterator();
while(ir.hasNext()) {
String s = ir.next();
System.out.println(s);
}
}
}
package test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
public class Test2 {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
Vector <String> vector =new Vector<>();
List<String> list2 = new Vector<>();
vector.add("일");
vector.add("이");
vector.add("삼");
System.out.println(vector.get(0));
System.out.println(vector.get(1));
System.out.println(vector.get(2));
LinkedList<String> myList = new LinkedList<>();
myList.add("A");
myList.add("B");
myList.add("C");
System.out.println(myList);
myList.add(1,"D");
System.out.println(myList);
Iterator<String> ir = vector.iterator();
while(ir.hasNext()) {
String s = ir.next();
System.out.println(s);
}
}
}
package test;
import java.util.HashSet;
import java.util.TreeSet;
public class Test3 {
public static void main(String[] args) {
HashSet<String> hashSet = new HashSet<>();
hashSet.add("홍길동");
hashSet.add("이길동");
hashSet.add("홍길동");
hashSet.add("삼길동");
System.out.println(hashSet);
TreeSet<String> treeSet = new TreeSet<>();
treeSet.add("홍길동");
treeSet.add("이길동");
treeSet.add("홍길동");
treeSet.add("삼길동");
System.out.println(treeSet);
}
}
package test;
import java.util.HashMap;
import java.util.TreeMap;
public class Test4 {
public static void main(String[] args) {
HashMap<Integer, String> hashMap = new HashMap<>();
hashMap.put(1, "홍길동");
hashMap.put(2, "이길동");
hashMap.put(3, "삼길동");
System.out.println(hashMap.get(1));
System.out.println(hashMap.get(2));
System.out.println(hashMap.get(3));
System.out.println(hashMap);
TreeMap<Integer, String> treeMap = new TreeMap<>();
treeMap.put(5, "오길동");
treeMap.put(7, "칠길동");
treeMap.put(6, "육길동");
System.out.println(treeMap);
}
}