Upload files to "/"
This commit is contained in:
19
TreeSet18a.java
Normal file
19
TreeSet18a.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//18a. write a java code to demonstrate tree set
|
||||||
|
import java.util.*;
|
||||||
|
public class TreeSet18a
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
TreeSet<String> brands = new TreeSet<String>();
|
||||||
|
brands.add("YSL");
|
||||||
|
brands.add("Prada");
|
||||||
|
brands.add("Louboutin");
|
||||||
|
brands.add("Maybellin");
|
||||||
|
brands.add("YSL");
|
||||||
|
Iterator<String> itr = brands.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
TreeSet18b.java
Normal file
19
TreeSet18b.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//18b. write a java code to demonstrate tree set
|
||||||
|
import java.util.*;
|
||||||
|
public class TreeSet18b
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
TreeSet<String> brands = new TreeSet<String>();
|
||||||
|
brands.add("YSL");
|
||||||
|
brands.add("Prada");
|
||||||
|
brands.add("Louboutin");
|
||||||
|
brands.add("null");
|
||||||
|
brands.add("YSL");
|
||||||
|
Iterator<String> itr = brands.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Vector14a.java
Normal file
18
Vector14a.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//14(a). write a java code to demonstrate vector
|
||||||
|
import java.util.*;
|
||||||
|
public class Vector14a
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Vector<String> name=new Vector<String>();
|
||||||
|
name.add("Misa");
|
||||||
|
name.add("Aditya");
|
||||||
|
name.add("Shyam");
|
||||||
|
name.add("Aisha");
|
||||||
|
Iterator<String> itr=name.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Vector14b.java
Normal file
21
Vector14b.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
public class Vector14b {
|
||||||
|
public static void main(String args[]){
|
||||||
|
Vector<String> groceryList = new Vector<String>();
|
||||||
|
groceryList.add("Bread");
|
||||||
|
groceryList.add("Milk");
|
||||||
|
groceryList.add("Eggs");
|
||||||
|
|
||||||
|
System.out.println("Item at index 0: " + groceryList.get(0));
|
||||||
|
System.out.println("Item at index 1: " + groceryList.get(1));
|
||||||
|
System.out.println("Item at index 2: " + groceryList.get(2));
|
||||||
|
|
||||||
|
System.out.println("Items in Grocery list: ");
|
||||||
|
for(String item: groceryList) {
|
||||||
|
System.out.println(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
itemList.remove(groceryList.get(2));
|
||||||
|
System.out.println("Size of grocery after removal: " + groceryList.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user