end of day, done till 13
This commit is contained in:
BIN
ArrayList11.class
Normal file
BIN
ArrayList11.class
Normal file
Binary file not shown.
22
ArrayList11.java
Normal file
22
ArrayList11.java
Normal file
@@ -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<String> 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());
|
||||
}
|
||||
}
|
||||
BIN
Iterator10.class
Normal file
BIN
Iterator10.class
Normal file
Binary file not shown.
15
Iterator10.java
Normal file
15
Iterator10.java
Normal file
@@ -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<String> nameList = new ArrayList<String>();
|
||||
nameList.add("Aditya");
|
||||
nameList.add("Vijay");
|
||||
nameList.add("Ravi");
|
||||
nameList.add("Ajay");
|
||||
Iterator itr = nameList.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
LinkedList13.class
Normal file
BIN
LinkedList13.class
Normal file
Binary file not shown.
24
LinkedList13.java
Normal file
24
LinkedList13.java
Normal file
@@ -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<String> 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());
|
||||
}
|
||||
}
|
||||
BIN
SortingArrayList12.class
Normal file
BIN
SortingArrayList12.class
Normal file
Binary file not shown.
21
SortingArrayList12.java
Normal file
21
SortingArrayList12.java
Normal file
@@ -0,0 +1,21 @@
|
||||
import java.util.*;
|
||||
|
||||
public class SortingArrayList12{
|
||||
public static void main(String[] args){
|
||||
ArrayList<String> playerList = new ArrayList<String>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
23
experiments/11exp.java
Normal file
23
experiments/11exp.java
Normal file
@@ -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<String> 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());
|
||||
}
|
||||
}
|
||||
BIN
experiments/Iterator10.class
Normal file
BIN
experiments/Iterator10.class
Normal file
Binary file not shown.
BIN
experiments/Iterator10exp.class
Normal file
BIN
experiments/Iterator10exp.class
Normal file
Binary file not shown.
23
experiments/Iterator10exp.java
Normal file
23
experiments/Iterator10exp.java
Normal file
@@ -0,0 +1,23 @@
|
||||
// exp
|
||||
import java.util.*;
|
||||
class Iterator10exp{
|
||||
public static void main(String args[]){
|
||||
ArrayList<String> nameList = new ArrayList<String>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
experiments/exp11.class
Normal file
BIN
experiments/exp11.class
Normal file
Binary file not shown.
29
experiments/exp11.java
Normal file
29
experiments/exp11.java
Normal file
@@ -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<String> 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());
|
||||
}
|
||||
}
|
||||
BIN
experiments/exp12.class
Normal file
BIN
experiments/exp12.class
Normal file
Binary file not shown.
34
experiments/exp12.java
Normal file
34
experiments/exp12.java
Normal file
@@ -0,0 +1,34 @@
|
||||
import java.util.*;
|
||||
|
||||
public class exp12{
|
||||
public static void main(String[] args){
|
||||
ArrayList<String> playerList = new ArrayList<String>();
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
src/10.png
Normal file
BIN
src/10.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
src/11.png
Normal file
BIN
src/11.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
src/12.png
Normal file
BIN
src/12.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
BIN
src/12exp.png
Normal file
BIN
src/12exp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
BIN
src/13.png
Normal file
BIN
src/13.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Reference in New Issue
Block a user