diff --git a/collection.java b/collection.java new file mode 100644 index 0000000..c1b1e29 --- /dev/null +++ b/collection.java @@ -0,0 +1,94 @@ +import java.util.*; + +public class collection{ + +static int id=0; + +ArrayList bscs = new ArrayList(); +HashMap hm= new HashMap(); +HashSet hs= new HashSet(); + +public void add(Student s) +{ + bscs.add(s); + System.out.println("Student Added in ArrayList "); + + hm.put(id++,s); + System.out.println("Student Added in HashMap "); + hs.add(s); + System.out.println("Student Added in HashSet "); + +} + +public void get(int index) +{ + System.out.println("Getting from arraylist..."); + bscs.get(index).displayStudentDetails(); + System.out.println("Getting from HasMap..."); + hm.get(index).displayStudentDetails(); + System.out.println("Getting from HashSet..."); + +} + + +public void printSize() +{ + System.out.println("Size of ArrayList is : "+ bscs.size()); + System.out.println("Size of HashMap is : "+ hm.size()); + System.out.println("Size of HashSet is : "+ hs.size()); + +} + + + +public void arraylistIterator() +{ + + System.out.println("Iterating through Array list"); + Iterator pointer = bscs.iterator(); + while(pointer.hasNext()) + pointer.next().displayStudentDetails(); + +} + + + + +public void hashSetIterator() +{ + + System.out.println("Iterating through Set"); + Iterator pointer = hs.iterator(); + while(pointer.hasNext()) + pointer.next().displayStudentDetails(); + +} + +public void hashMapIterator() +{ + + System.out.println("Iterating through Map"); + Iterator> pointer = hm.entrySet().iterator(); + while(pointer.hasNext()) + { + pointer.next().getValue().displayStudentDetails(); + } +} + + + + +public static void main(String args[]) +{ + collection a = new collection(); + +a.add(new Student("name","fatherName","address",10)); +a.get(0); +a.printSize(); +a.arraylistIterator(); +a.hashSetIterator(); +a.hashMapIterator(); +} + + +} \ No newline at end of file diff --git a/lab_5 (1).pdf b/lab_5 (1).pdf new file mode 100644 index 0000000..aa722d5 Binary files /dev/null and b/lab_5 (1).pdf differ