first commit
This commit is contained in:
23
TestJavaCollection4.java
Normal file
23
TestJavaCollection4.java
Normal file
@@ -0,0 +1,23 @@
|
||||
// Write a java code to demo stack
|
||||
import java.util.*;
|
||||
public class TestJavaCollection4{
|
||||
public static void main(String args[]){
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.push("Ayush");
|
||||
stack.push("Garvit");
|
||||
stack.push("Amit");
|
||||
stack.push("Ashish");
|
||||
stack.push("Garvit");
|
||||
Iterator<String> itr=stack.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
String topElement = stack.peek();
|
||||
System.out.println("The top element of the stack is: "+ topElement);
|
||||
stack.pop()
|
||||
System.out.println("After POP");
|
||||
for(String element : stack){
|
||||
System.out.println(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
TestJavaCollection7.java
Normal file
19
TestJavaCollection7.java
Normal file
@@ -0,0 +1,19 @@
|
||||
//Hashset
|
||||
import java.util.*;
|
||||
public class TestJavaCollection7{
|
||||
public static void main(String args[]){
|
||||
HashSet<String> set=new HashSet<String>();
|
||||
set.add("Ravi");
|
||||
set.add("Vijay");
|
||||
set.add("Ravi");
|
||||
set.add("Ajay");
|
||||
set.add(null);
|
||||
|
||||
Iterator<String>itr=set.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
16
TestJavaCollection8.java
Normal file
16
TestJavaCollection8.java
Normal file
@@ -0,0 +1,16 @@
|
||||
//WAJ to demo linkedhash set
|
||||
import java.util.*;
|
||||
public class TestJavaCollection8{
|
||||
public static void main(String args[]){
|
||||
LinkedHashSet<String> set=new LinkedHashSet<String>();
|
||||
set.add("Ravi");
|
||||
set.add("Vijay");
|
||||
set.add("ravi");
|
||||
set.add("Ajay");
|
||||
|
||||
Iterator<String> itr=set.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
17
TestJavaCollection8b.java
Normal file
17
TestJavaCollection8b.java
Normal file
@@ -0,0 +1,17 @@
|
||||
/WAJ to demo linkedhash set
|
||||
import java.util.*;
|
||||
public class TestJavaCollection8{
|
||||
public static void main(String args[]){
|
||||
LinkedHashSet<String> set=new LinkedHashSet<String>();
|
||||
set.add("Ravi");
|
||||
set.add("Vijay");
|
||||
set.add("");
|
||||
set.add("Ravi");
|
||||
set.add("Ajay");
|
||||
|
||||
Iterator<String> itr=set.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
17
TestJavaCollection8c.java
Normal file
17
TestJavaCollection8c.java
Normal file
@@ -0,0 +1,17 @@
|
||||
//WAJ to demo linkedhash set
|
||||
import java.util.*;
|
||||
public class TestJavaCollection8c{
|
||||
public static void main(String args[]){
|
||||
LinkedHashSet<String> set=new LinkedHashSet<String>();
|
||||
set.add("Ravi");
|
||||
set.add("Vijay");
|
||||
set.add(null);
|
||||
set.add("Ravi");
|
||||
set.add("Ajay");
|
||||
|
||||
Iterator<String> itr=set.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
18
TestJavaCollection9.java
Normal file
18
TestJavaCollection9.java
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
//WAJ to demo Treeset
|
||||
import java.util.*;
|
||||
public class TestJavaCollection9{
|
||||
public static void main(String args[]){
|
||||
TreeSet<String> set=new TreeSet<String>();
|
||||
set.add("Ravi");
|
||||
set.add("Vijay");
|
||||
set.add("Ajay");
|
||||
set.add("Ravi");
|
||||
set.add("Ajay");
|
||||
|
||||
Iterator<String> itr=set.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
18
TestJavaCollection9b.java
Normal file
18
TestJavaCollection9b.java
Normal file
@@ -0,0 +1,18 @@
|
||||
//WAJ to demo Treeset
|
||||
import java.util.*;
|
||||
public class TestJavaCollection9b{
|
||||
public static void main(String args[]){
|
||||
TreeSet<String> set=new TreeSet<String>();
|
||||
set.add("Ravi");
|
||||
set.add("Vijay");
|
||||
set.add("");
|
||||
set.add(null);
|
||||
set.add("Ravi");
|
||||
set.add("Ajay");
|
||||
|
||||
Iterator<String> itr=set.iterator();
|
||||
while(itr.hasNext()){
|
||||
System.out.println(itr.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user