diff --git a/11.java b/11.java new file mode 100644 index 0000000..ae159a5 --- /dev/null +++ b/11.java @@ -0,0 +1 @@ +// 11. write a java program to demonstrate ArrayList \ No newline at end of file diff --git a/ArrayList11.class b/ArrayList11.class new file mode 100644 index 0000000..1807f15 Binary files /dev/null and b/ArrayList11.class differ diff --git a/ArrayList11.java b/ArrayList11.java new file mode 100644 index 0000000..ea451bb --- /dev/null +++ b/ArrayList11.java @@ -0,0 +1,22 @@ +// 11. write a java program to demonstrate ArrayList +import java.util.ArrayList; +public class ArrayList11 { + public static void main(String[] args){ + ArrayList elementList = new ArrayList<>(); + elementList.add("Hydrogen"); + elementList.add("Helium"); + elementList.add("Lithium"); + + System.out.println("Element at index 0: " + elementList.get(0)); + System.out.println("Element at index 1: " + elementList.get(1)); + System.out.println("Element at index 2: " + elementList.get(2)); + + System.out.println("Periodic Table Elements: "); + for(String element: elementList) { + System.out.println(element); + } + + elementList.remove(elementList.get(2)); + System.out.println("Size of elementList after removal of Lithium is: " + elementList.size()); + } +} \ No newline at end of file diff --git a/Iterator10.class b/Iterator10.class new file mode 100644 index 0000000..b57426b Binary files /dev/null and b/Iterator10.class differ diff --git a/Iterator10.java b/Iterator10.java new file mode 100644 index 0000000..3b2da91 --- /dev/null +++ b/Iterator10.java @@ -0,0 +1,15 @@ +// 10. write a javac code to implement iterator to access collection element +import java.util.*; +class Iterator10{ +public static void main(String args[]){ + ArrayList nameList = new ArrayList(); + nameList.add("Aditya"); + nameList.add("Vijay"); + nameList.add("Ravi"); + nameList.add("Ajay"); + Iterator itr = nameList.iterator(); + while(itr.hasNext()){ + System.out.println(itr.next()); + } + } +} \ No newline at end of file diff --git a/LinkedList13.class b/LinkedList13.class new file mode 100644 index 0000000..ff36e43 Binary files /dev/null and b/LinkedList13.class differ diff --git a/LinkedList13.java b/LinkedList13.java new file mode 100644 index 0000000..0ea1eb6 --- /dev/null +++ b/LinkedList13.java @@ -0,0 +1,24 @@ +// 13. write a java program to demonstrate Linked List + +import java.util.LinkedList; + +public class LinkedList13{ + public static void main(String[] args){ + LinkedList nobelGasList = new LinkedList<>(); + nobelGasList.add("Argon"); + nobelGasList.add("xedon"); + nobelGasList.add("radon"); + + System.out.println("Element at index 0: " + nobelGasList.get(0)); + System.out.println("Element at index 1: " + nobelGasList.get(1)); + System.out.println("Element at index 2: " + nobelGasList.get(2)); + + System.out.println("Nobel Gases: "); + for(String gas: nobelGasList) { + System.out.println(gas); + } + + nobelGasList.remove(nobelGasList.get(2)); + System.out.println("Size of elementList after removal of radon is: " + nobelGasList.size()); + } +} \ No newline at end of file diff --git a/SortingArrayList12.class b/SortingArrayList12.class new file mode 100644 index 0000000..5c3a310 Binary files /dev/null and b/SortingArrayList12.class differ diff --git a/SortingArrayList12.java b/SortingArrayList12.java new file mode 100644 index 0000000..20da87c --- /dev/null +++ b/SortingArrayList12.java @@ -0,0 +1,21 @@ +import java.util.*; + +public class SortingArrayList12{ + public static void main(String[] args){ + ArrayList playerList = new ArrayList(); + playerList.add("Sachin Tendulkar"); + playerList.add("Rahul Dravid"); + playerList.add("Virender Sehwag"); + playerList.add("MS Dhoni"); + playerList.add("Virat Kohli"); + playerList.add("Anil Kumble"); + playerList.add("Yuvraj Singh"); + playerList.add("Kapil Dev"); + playerList.add("Sunil Gavaskar"); + playerList.add("Javagal Srinath"); + + System.out.println("Unsorted List: \n" + playerList); + Collections.sort(playerList); + System.out.println("\nSorted List: \n" + playerList); + } +} \ No newline at end of file diff --git a/experiments/11exp.java b/experiments/11exp.java new file mode 100644 index 0000000..e63162f --- /dev/null +++ b/experiments/11exp.java @@ -0,0 +1,23 @@ +// 11. write a java program to demonstrate ArrayList +import java.util.ArrayList; +public class exp11 { + public static void main(String[] args){ + ArrayList elementList = new ArrayList<>(); + elementList.add("Hydrogen"); + elementList.add("Helium"); + elementList.add("Lithium"); + + System.out.println("Element at index 0: " + elementList.get(0)); + System.out.println("Element at index 1: " + elementList.get(1)); + System.out.println("Element at index 2: " + elementList.get(2)); + + elementList.remove("Nitrogen"); + System.out.println("Periodic Table Elements: "); + for(String element: elementList) { + System.out.println(element); + } + + elementList.remove(elementList.get(2)); + System.out.println("Size of elementList after removal of Lithium is: " + elementList.size()); + } +} \ No newline at end of file diff --git a/experiments/Iterator10.class b/experiments/Iterator10.class new file mode 100644 index 0000000..dff31ad Binary files /dev/null and b/experiments/Iterator10.class differ diff --git a/experiments/Iterator10exp.class b/experiments/Iterator10exp.class new file mode 100644 index 0000000..1a4e152 Binary files /dev/null and b/experiments/Iterator10exp.class differ diff --git a/experiments/Iterator10exp.java b/experiments/Iterator10exp.java new file mode 100644 index 0000000..e1d56a4 --- /dev/null +++ b/experiments/Iterator10exp.java @@ -0,0 +1,23 @@ +// exp +import java.util.*; +class Iterator10exp{ +public static void main(String args[]){ + ArrayList nameList = new ArrayList(); + nameList.add("Aditya"); + nameList.add("Vijay"); + nameList.add("Ravi"); + nameList.add("Ajay"); + + String name = "Ajay"; + String name2 = "Misa"; + + nameList.add(name2); + nameList.remove(nameList.get(2)); + nameList.remove(name); + + Iterator itr = nameList.iterator(); + while(itr.hasNext()){ + System.out.println(itr.next()); + } + } +} \ No newline at end of file diff --git a/experiments/exp11.class b/experiments/exp11.class new file mode 100644 index 0000000..9ef3c40 Binary files /dev/null and b/experiments/exp11.class differ diff --git a/experiments/exp11.java b/experiments/exp11.java new file mode 100644 index 0000000..b1f4ad5 --- /dev/null +++ b/experiments/exp11.java @@ -0,0 +1,29 @@ +// 11. write a java program to demonstrate ArrayList +import java.util.*; +public class exp11 { + public static void main(String[] args){ + ArrayList elementList = new ArrayList<>(); + elementList.add("Hydrogen"); + elementList.add("Helium"); + elementList.add("Lithium"); + + System.out.println("Element at index 0: " + elementList.get(0)); + System.out.println("Element at index 1: " + elementList.get(1)); + System.out.println("Element at index 2: " + elementList.get(2)); + + elementList.remove("Nitrogen"); + System.out.println("Periodic Table Elements: "); + for(String element: elementList) { + System.out.println(element); + } + + elementList.remove(elementList.get(2)); + System.out.println("Size of elementList after removal of Lithium is: " + elementList.size()); + + Iterator pdt = elementList.iterator(); + System.out.println(pdt.next()); + System.out.println(pdt.next()); + //System.out.println(pdt.next()); --> NoSuchElementException + //System.out.println(pdt.next()); + } +} \ No newline at end of file diff --git a/experiments/exp12.class b/experiments/exp12.class new file mode 100644 index 0000000..3decc2f Binary files /dev/null and b/experiments/exp12.class differ diff --git a/experiments/exp12.java b/experiments/exp12.java new file mode 100644 index 0000000..3fd3259 --- /dev/null +++ b/experiments/exp12.java @@ -0,0 +1,34 @@ +import java.util.*; + +public class exp12{ + public static void main(String[] args){ + ArrayList playerList = new ArrayList(); + playerList.add("Sachin Tendulkar"); + playerList.add("Rahul Dravid"); + playerList.add("Virender Sehwag"); + playerList.add("MS Dhoni"); + playerList.add("Virat Kohli"); + playerList.add("Anil Kumble"); + playerList.add("Yuvraj Singh"); + playerList.add("Kapil Dev"); + playerList.add("Sunil Gavaskar"); + playerList.add("Javagal Srinath"); + + + System.out.println("Unsorted List: \n"); + Iterator pre = playerList.iterator(); + while(pre.hasNext()){ + System.out.println(pre.next()); + } + + + Collections.sort(playerList); + System.out.println("\nSorted List: \n"); + + Iterator post = playerList.iterator(); + while(post.hasNext()){ + System.out.println(post.next()); + } + + } +} \ No newline at end of file diff --git a/src/10.png b/src/10.png new file mode 100644 index 0000000..5a72046 Binary files /dev/null and b/src/10.png differ diff --git a/src/11.png b/src/11.png new file mode 100644 index 0000000..7128722 Binary files /dev/null and b/src/11.png differ diff --git a/src/12.png b/src/12.png new file mode 100644 index 0000000..c464dce Binary files /dev/null and b/src/12.png differ diff --git a/src/12exp.png b/src/12exp.png new file mode 100644 index 0000000..6bb75e8 Binary files /dev/null and b/src/12exp.png differ diff --git a/src/13.png b/src/13.png new file mode 100644 index 0000000..ebc2ce1 Binary files /dev/null and b/src/13.png differ