๐ 2023๋ 12์ 13์ผ
[java 7์ผ์ฐจ]
//Set<String> mySet = new HashSet<>(list); list๋ฅผ ์ธ์๊ฐ์ผ๋ก ๋ฐ์ ํ์ค ์ฒ๋ฆฌ ๊ฐ๋ฅ Set<String> mySet = new HashSet<>(); mySet.add("h"); mySet.add("h"); mySet.add("e"); mySet.add("l"); mySet.add("l"); mySet.add("l"); mySet.add("o"); List<String> list = new ArrayList<>(); list.add("basketball"); list.add("basketball"); list.add("basketball"); list.add("baseball"); list.add("baseball"); list.add("tennis"); list.add("tennis"); list.add("tennis"); mySet.addAll(list); String[] arr = {"java", "python","c++", "java", "python" }; Set<String> mySet2 = new HashSet<>(Arrays.asList(arr)); mySet2.remove("java"); Set<String> mySet3 = new HashSet<>(Arrays.asList("java", "python", "js")); Set<String> mySet4 = new HashSet<>(Arrays.asList("java", "html", "css")); // ๊ต์งํฉ retainAll Set<String> temp1 = new HashSet<>(mySet3); temp1.retainAll(mySet4); // ํฉ์งํฉ addAll Set<String> temp2 = new HashSet<>(mySet3); temp1.addAll(mySet4); // ์ฐจ์งํฉ removeAll Set<String> temp3 = new HashSet<>(mySet3); temp1.removeAll(mySet4); // ์๋ ์ ๋ ฌ Set Set<String> mySet5 = new TreeSet<>();
Stack<Integer> stack = new Stack<>(); stack.push(10); System.out.println(stack.pop()); System.out.println(stack.peek()); System.out.println(stack.size()); System.out.println(stack.isEmpty());
Queue<Integer> q = new LinkedList<>(); q.add(10); System.out.println(q.poll());
// ๊ธธ์ด์ ์ ํ์ด ์๋ ํ : ArrayBlockingQueue Queue<String> q = new ArrayBlockingQueue<>(3); // add: ๊ธธ์ด๊ฐ ๋ค ์ฐจ๋ฉด error // offer : ๊ณต๊ฐ์ด ์ถฉ๋ถํ ๋๋ง add q.add("1"); q.add("2"); q.add("3"); // q.add("4"); ์๋ฌ q.offer("4");
Queue<Integer> pq = new PriorityQueue<>(); pq.add(3); pq.add(1); pq.add(2);