diff --git a/.idea/misc.xml b/.idea/misc.xml index 91063aa..07115cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index dca381d..4b46c05 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ A beginner's guide to Learn Java Collections Framework Collections Framework in 1 video +![collection-hierarchy](https://static.javatpoint.com/images/java-collection-hierarchy.png?raw=true) +![Simplified](https://www.logicbig.com/tutorials/core-java-tutorial/java-collections/java-collection-cheatsheet/images/collection-opts.png?raw=true) +![Simplified](https://github.com/SafiBadi/Collections-Framework/blob/master/img/Screenshot%20(65).png?raw=true) + + ## Topics included: * Collection Interface diff --git a/img/Screenshot (65).png b/img/Screenshot (65).png new file mode 100644 index 0000000..235a362 Binary files /dev/null and b/img/Screenshot (65).png differ diff --git a/out/production/LearnCollectionFramework/LearnArrayDeque.class b/out/production/LearnCollectionFramework/LearnArrayDeque.class index 77e6018..5fe9fff 100644 Binary files a/out/production/LearnCollectionFramework/LearnArrayDeque.class and b/out/production/LearnCollectionFramework/LearnArrayDeque.class differ diff --git a/out/production/LearnCollectionFramework/LearnArrayList.class b/out/production/LearnCollectionFramework/LearnArrayList.class index 8ee145d..3c1bafe 100644 Binary files a/out/production/LearnCollectionFramework/LearnArrayList.class and b/out/production/LearnCollectionFramework/LearnArrayList.class differ diff --git a/out/production/LearnCollectionFramework/LearnArraysClass.class b/out/production/LearnCollectionFramework/LearnArraysClass.class index 15eda95..6b0b552 100644 Binary files a/out/production/LearnCollectionFramework/LearnArraysClass.class and b/out/production/LearnCollectionFramework/LearnArraysClass.class differ diff --git a/out/production/LearnCollectionFramework/LearnCollectionsClass$1.class b/out/production/LearnCollectionFramework/LearnCollectionsClass$1.class deleted file mode 100644 index 73eb474..0000000 Binary files a/out/production/LearnCollectionFramework/LearnCollectionsClass$1.class and /dev/null differ diff --git a/out/production/LearnCollectionFramework/LearnCollectionsClass.class b/out/production/LearnCollectionFramework/LearnCollectionsClass.class index 89cf485..c238c30 100644 Binary files a/out/production/LearnCollectionFramework/LearnCollectionsClass.class and b/out/production/LearnCollectionFramework/LearnCollectionsClass.class differ diff --git a/out/production/LearnCollectionFramework/LearnLinkedListQueue.class b/out/production/LearnCollectionFramework/LearnLinkedListQueue.class deleted file mode 100644 index 8ab0ccd..0000000 Binary files a/out/production/LearnCollectionFramework/LearnLinkedListQueue.class and /dev/null differ diff --git a/out/production/LearnCollectionFramework/LearnLinkedListUsingList.class b/out/production/LearnCollectionFramework/LearnLinkedListUsingList.class new file mode 100644 index 0000000..36c6c33 Binary files /dev/null and b/out/production/LearnCollectionFramework/LearnLinkedListUsingList.class differ diff --git a/out/production/LearnCollectionFramework/LearnLinkedListUsingQueue.class b/out/production/LearnCollectionFramework/LearnLinkedListUsingQueue.class new file mode 100644 index 0000000..38c52dc Binary files /dev/null and b/out/production/LearnCollectionFramework/LearnLinkedListUsingQueue.class differ diff --git a/out/production/LearnCollectionFramework/LearnMap.class b/out/production/LearnCollectionFramework/LearnMap.class index c4bf933..20fbca5 100644 Binary files a/out/production/LearnCollectionFramework/LearnMap.class and b/out/production/LearnCollectionFramework/LearnMap.class differ diff --git a/out/production/LearnCollectionFramework/LearnPriorityQueue.class b/out/production/LearnCollectionFramework/LearnPriorityQueue.class index 7fac506..a241b28 100644 Binary files a/out/production/LearnCollectionFramework/LearnPriorityQueue.class and b/out/production/LearnCollectionFramework/LearnPriorityQueue.class differ diff --git a/out/production/LearnCollectionFramework/LearnSet.class b/out/production/LearnCollectionFramework/LearnSet.class index cbd504d..03c2fdc 100644 Binary files a/out/production/LearnCollectionFramework/LearnSet.class and b/out/production/LearnCollectionFramework/LearnSet.class differ diff --git a/out/production/LearnCollectionFramework/LearnStack.class b/out/production/LearnCollectionFramework/LearnStack.class index 20f32c7..ad44e7f 100644 Binary files a/out/production/LearnCollectionFramework/LearnStack.class and b/out/production/LearnCollectionFramework/LearnStack.class differ diff --git a/out/production/LearnCollectionFramework/Map2.class b/out/production/LearnCollectionFramework/Map2.class new file mode 100644 index 0000000..4c3f702 Binary files /dev/null and b/out/production/LearnCollectionFramework/Map2.class differ diff --git a/out/production/LearnCollectionFramework/Student.class b/out/production/LearnCollectionFramework/Student.class index 7124400..5472685 100644 Binary files a/out/production/LearnCollectionFramework/Student.class and b/out/production/LearnCollectionFramework/Student.class differ diff --git a/src/LearnArrayDeque.java b/src/LearnArrayDeque.java deleted file mode 100644 index 98f845f..0000000 --- a/src/LearnArrayDeque.java +++ /dev/null @@ -1,31 +0,0 @@ -import java.util.ArrayDeque; - -public class LearnArrayDeque { - - public static void main(String[] args) { - - ArrayDeque adq = new ArrayDeque<>(); - - adq.offer(23); - adq.offerFirst(12); - adq.offerLast(45); - adq.offer(26); - - System.out.println(adq); - - System.out.println(adq.peek()); - System.out.println(adq.peekFirst()); - System.out.println(adq.peekLast()); - - System.out.println(adq.poll()); - System.out.println("poll() " +adq); - - System.out.println(adq.pollFirst()); - System.out.println("pollFirst() " +adq); - - System.out.println(adq.pollLast()); - System.out.println("pollLast() " +adq); - - } - -} diff --git a/src/LearnArrayList.java b/src/LearnArrayList.java deleted file mode 100644 index 91f55c1..0000000 --- a/src/LearnArrayList.java +++ /dev/null @@ -1,75 +0,0 @@ -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -public class LearnArrayList { - - public static void main(String[] args) { - - List list = new LinkedList<>(); - list.add(1); - list.add(2); - list.add(3); - System.out.println(list); - - list.add(4); // This will add 4 at the end of the List. - System.out.println(list); - - list.add(1, 50); // This will add 50 at index 1. All the other elements will be shifted to right. - System.out.println(list); - - List newList = new ArrayList(); // Creating a new List which will be added to original list. - newList.add(150); - newList.add(160); - - list.addAll(newList); // This will add all the elements present in newList to list. - System.out.println(list); - - System.out.println(list.get(1)); - -// List list = new ArrayList<>(); -// list.add(10); -// list.add(20); -// list.add(30); -// list.add(40); -// list.add(50); -// list.add(60); -// list.add(70); -// list.add(80); -// -// System.out.println(list); -// -// for (int i = 0; i < list.size(); i++) { -// System.out.println("the element is " + list.get(i)); -// } -// -// for (Integer element: list) { -// System.out.println("foreach element is " + element); -// } -// -// Iterator it = list.iterator(); -// -// while (it.hasNext()) { -// System.out.println("iterator " + it.next()); -// } - -// list.set(2, 1000); -// -// System.out.println(list); -// -// System.out.println(list.contains(500)); - -// list.remove(1); // This will remove the element at index 1 i.e 20. -// System.out.println(list); -// -// list.remove(Integer.valueOf(30)); // This will remove 30 from the list -// System.out.println(list); -// -// list.clear(); //This will remove all the elements from the list. -// System.out.println(list); - - - - } -} diff --git a/src/LearnArraysClass.java b/src/LearnArraysClass.java deleted file mode 100644 index b62d5f2..0000000 --- a/src/LearnArraysClass.java +++ /dev/null @@ -1,27 +0,0 @@ -import java.util.Arrays; - -public class LearnArraysClass { - - public static void main(String[] args) { - -// int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; -// int index = Arrays.binarySearch(numbers, 4); -// -// System.out.println("The index of element 4 in the array is " + index); - - Integer[] numbers = { 10, 2, 32, 12, 15, 76, 17, 48, 79, 9 }; - Arrays.sort(numbers); - - Arrays.parallelSort(numbers); - // 8192 - - Arrays.fill(numbers, 12); - - for (int i : numbers) { - System.out.print(i + " "); - } - - - - } -} diff --git a/src/LearnCollectionsClass.java b/src/LearnCollectionsClass.java deleted file mode 100644 index 9379a53..0000000 --- a/src/LearnCollectionsClass.java +++ /dev/null @@ -1,48 +0,0 @@ -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -public class LearnCollectionsClass { - - public static void main(String[] args) { - - List list = new ArrayList<>(); - - list.add(new Student("Anuj", 2)); - list.add(new Student("Ramesh", 4)); - list.add(new Student("Shivam", 3)); - list.add(new Student("Rohit", 1)); - - Student s1 = new Student("Anuj", 2); - Student s2 = new Student("Rohit", 3); - -// System.out.println((s1.compareTo(s2))); - - System.out.println(list); - - Collections.sort(list, (o1, o2) -> o1.name.compareTo(o2.name)); - - System.out.println(list); - - -// List list = new ArrayList<>(); -// list.add(34); -// list.add(12); -// list.add(9); -// list.add(9); -// list.add(9); -// list.add(76); -// list.add(29); -// list.add(75); -// -//// System.out.println("min element " + Collections.min(list)); -//// System.out.println("max element " + Collections.max(list)); -//// System.out.println(Collections.frequency(list, 9)); -// -// Collections.sort(list, Comparator.reverseOrder()); -// -// System.out.println(list); - } - -} diff --git a/src/LearnLinkedListQueue.java b/src/LearnLinkedListQueue.java deleted file mode 100644 index c11811a..0000000 --- a/src/LearnLinkedListQueue.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.util.LinkedList; -import java.util.Queue; - -public class LearnLinkedListQueue { - - public static void main(String[] args) { - - Queue queue = new LinkedList<>(); - - queue.offer(12); - queue.offer(24); - queue.offer(36); - - System.out.println(queue); - - System.out.println(queue.poll()); - - System.out.println(queue); - - System.out.println(queue.peek()); - - } -} diff --git a/src/LearnMap.java b/src/LearnMap.java deleted file mode 100644 index 008c5eb..0000000 --- a/src/LearnMap.java +++ /dev/null @@ -1,46 +0,0 @@ -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; - -public class LearnMap { - - public static void main(String[] args) { - - Map numbers = new TreeMap<>(); - - numbers.put("One", 1); - numbers.put("Two", 2); - numbers.put("Three", 3); - numbers.put("Four", 4); - numbers.put("Five", 5); - - - numbers.remove("Three"); - -// if(!numbers.containsKey("Two")) { -// numbers.put("Two", 23); -// } - -// numbers.putIfAbsent("Two", 23); - System.out.println(numbers); - System.out.println(numbers.containsValue(3)); - - System.out.println(numbers.isEmpty()); - -// for (Map.Entry e: numbers.entrySet()) { -// System.out.println(e); -// -// System.out.println(e.getKey()); -// System.out.println(e.getValue()); -// } -// -// for (String key: numbers.keySet()) { -// System.out.println(key); -// } -// -// for(Integer value: numbers.values()) { -// System.out.println(value); -// } - - } -} diff --git a/src/LearnPriorityQueue.java b/src/LearnPriorityQueue.java deleted file mode 100644 index 553738d..0000000 --- a/src/LearnPriorityQueue.java +++ /dev/null @@ -1,24 +0,0 @@ -import java.util.Comparator; -import java.util.PriorityQueue; -import java.util.Queue; - -public class LearnPriorityQueue { - - public static void main(String[] args) { - - Queue pq = new PriorityQueue<>(Comparator.reverseOrder()); - - pq.offer(40); - pq.offer(12); - pq.offer(24); - pq.offer(36); - - System.out.println(pq); - pq.poll(); - System.out.println(pq); - - System.out.println(pq.peek()); - - } - -} diff --git a/src/LearnSet.java b/src/LearnSet.java deleted file mode 100644 index e91d53f..0000000 --- a/src/LearnSet.java +++ /dev/null @@ -1,52 +0,0 @@ -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.TreeSet; - -public class LearnSet { - - public static void main(String[] args) { - - Set studentSet = new HashSet<>(); - - studentSet.add(new Student("Anuj", 2)); - studentSet.add(new Student("Ramesh", 4)); - studentSet.add(new Student("Shivam", 3)); - - studentSet.add(new Student("Rohit", 2)); - - Student s1 = new Student("Anuj", 2); - Student s2 = new Student("Rohit", 2); - - System.out.println(s1.equals(s2)); - System.out.println(studentSet); - -// Set set = new HashSet<>(); -// Set set = new LinkedHashSet<>(); - -// Set set = new TreeSet<>(); -// -// set.add(32); -// set.add(2); -// set.add(54); -// set.add(21); -// set.add(65); -// -// System.out.println(set); -// -// set.remove(54); -// -// System.out.println(set); -// -// System.out.println(set.contains(21)); -// -// System.out.println(set.isEmpty()); -// -// System.out.println(set.size()); -// -// set.clear(); -// -// System.out.println(set); - - } -} diff --git a/src/LearnStack.java b/src/LearnStack.java deleted file mode 100644 index 09af75e..0000000 --- a/src/LearnStack.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.util.Stack; - -public class LearnStack { - - public static void main(String[] args) { - Stack animals= new Stack<>(); - - animals.push("Lion"); - animals.push("Dog"); - animals.push("Horse"); - animals.push("Cat"); - - System.out.println("Stack: " + animals); - - System.out.println(animals.peek()); - - animals.pop(); - - System.out.println("Stack: " + animals); - - System.out.println(animals.peek()); - } -} diff --git a/src/Student.java b/src/Student.java deleted file mode 100644 index 8ecaa2d..0000000 --- a/src/Student.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.util.Comparator; -import java.util.Objects; - -public class Student implements Comparable { - - String name; - int rollNo; - - public Student(String name, int rollNo) { - this.name = name; - this.rollNo = rollNo; - } - - @Override - public String toString() { - return "Student{" + - "name='" + name + '\'' + - ", rollNo=" + rollNo + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Student student = (Student) o; - return rollNo == student.rollNo; - } - - @Override - public int hashCode() { - return Objects.hash(rollNo); - } - - @Override - public int compareTo(Student that) { - return this.rollNo - that.rollNo; - } -}