๐กArrayList<T>
import java.util.*;
public class ArraryListAll {
public static void main(String[] args) {
ArrayList<Integer> arrList = new ArrayList<>();
arrList.add(40);
arrList.add(20);
arrList.add(30);
arrList.add(10);
System.out.println(arrList.add(30));
for(int i = 0; i < arrList.size(); i++) {
System.out.println(arrList.get(i));
}
arrList.remove(1);
for(int e : arrList) {
System.out.println(e + " ");
}
Collections.sort(arrList);
Iterator<Integer> iter = arrList.iterator();
while(iter.hasNext()) {
System.out.println(iter.next() + " ");
}
arrList.set(0, 20);
System.out.println("๋ฆฌ์คํธ์ ํฌ๊ธฐ: " + arrList.size());
}
}
๐กHashSet<T>
import java.util.*;
public class SetAll {
public static void main(String[] args) {
HashSet<String> hs1 = new HashSet<>();
HashSet<String> hs2 = new HashSet<>();
hs1.add("ํ๊ธธ๋");
hs1.add("์ด์์ ");
System.out.println(hs1.add("์๊บฝ์ "));
System.out.println(hs1.add("์๊บฝ์ "));
for(String e : hs1) {
System.out.println(e + " ");
}
hs2.add("์๊บฝ์ ");
hs2.add("ํ๊ธธ๋");
hs2.add("์ด์์ ");
Iterator<String> ite = hs2.iterator();
while(ite.hasNext()) {
System.out.println(ite.next() + " ");
}
System.out.println("์งํฉ์ ํฌ๊ธฐ: " + hs2.size());
}
}