LabWork
24
AreaG.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//program 9 b
|
||||||
|
public class AreaG<T> {
|
||||||
|
|
||||||
|
private T t;
|
||||||
|
|
||||||
|
public void add(T t) {
|
||||||
|
this.t = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AreaG<Integer> rectangle = new AreaG<>();
|
||||||
|
AreaG<Double> circle = new AreaG<>();
|
||||||
|
|
||||||
|
rectangle.add(10);
|
||||||
|
circle.add(2.5);
|
||||||
|
|
||||||
|
System.out.println("Area of a rectangle is: " +rectangle.get());
|
||||||
|
System.out.println("Area of a Circle is: " +circle.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
ArrayList11.class
Normal file
BIN
CatArrayList.class
Normal file
16
GenericClass.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//9A write a java code for generic class
|
||||||
|
public class GenericClass<T1, T2>
|
||||||
|
{
|
||||||
|
public void display(T1 var1, T2 var2)
|
||||||
|
{
|
||||||
|
System.out.println("Name: " + var1 + ", ID: " + var2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
GenericClass<String, Integer> obj1 = new GenericClass<String, Integer>();
|
||||||
|
GenericClass<Integer, Integer> obj2 = new GenericClass<Integer, Integer>();
|
||||||
|
|
||||||
|
obj1.display("Misa", 101);
|
||||||
|
obj2.display(201, 301);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
GenericMethod1.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
public class GenericMethod1
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Integer[] intArray = {1, 2 , 3 ,4 ,5};
|
||||||
|
String[] stringArray = {"Hello", "Adi", "!"};
|
||||||
|
System.out.print("Integer Array:");
|
||||||
|
printArray(intArray);
|
||||||
|
System.out.print("String Array:");
|
||||||
|
printArray(stringArray);
|
||||||
|
}
|
||||||
|
public static <T> void printArray(T[] arr)
|
||||||
|
{
|
||||||
|
for(T element : arr)
|
||||||
|
{
|
||||||
|
System.out.print(element + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
19
GenericMethod2.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
public class GenericMethod2
|
||||||
|
{
|
||||||
|
public static <T extends Comparable<T>> T findMax(T x, T y)
|
||||||
|
{
|
||||||
|
return x.compareTo(y) > 0 ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Integer maxInt = findMax(5,10);
|
||||||
|
System.out.println("Maxim7um of 5 and 10 is: " +maxInt);
|
||||||
|
|
||||||
|
Double maxDouble = findMax(3.5, 7.8);
|
||||||
|
System.out.println("Maximum of 3.5 and 7.8 is: " +maxDouble);
|
||||||
|
|
||||||
|
String maxString = findMax("apple", "banana");
|
||||||
|
System.out.println("Maximum of 'apple' and 'banana' is: " +maxString);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
GenericMethodTest.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//write a java code for generic method
|
||||||
|
public class GenericMethodTest
|
||||||
|
{
|
||||||
|
public static <E> void printarray(E[] inputarray)
|
||||||
|
{
|
||||||
|
for(E element :inputarray)
|
||||||
|
{
|
||||||
|
System.out.printf("%s", element);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Integer[] intarray = {1,2,3,4,5};
|
||||||
|
Character[] chararray = {'a','b','c','d'};
|
||||||
|
System.out.println("Array in integer:");
|
||||||
|
printarray(intarray);
|
||||||
|
System.out.println("Array in character");
|
||||||
|
printarray(chararray);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
HashSet16.class
Normal file
19
HashSet16.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//16. write a java code to demonstrate HashSet
|
||||||
|
import java.util.*;
|
||||||
|
public class HashSet16
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
HashSet<String> drinks = new HashSet<String>();
|
||||||
|
drinks.add("Cranberry Juice");
|
||||||
|
drinks.add("Mango Lassi");
|
||||||
|
drinks.add("Cranberry Juice");
|
||||||
|
drinks.add("Mixed fruit Juice");
|
||||||
|
|
||||||
|
Iterator<String> itr = drinks.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
JavaCollection1.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//10 write a java code to implement iterator to acess collection element
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
class TestJavaCollection1
|
||||||
|
{
|
||||||
|
public static void main(String args[])
|
||||||
|
{
|
||||||
|
ArrayList<String> list = new ArrayList<String>(); // Creating arraylist
|
||||||
|
|
||||||
|
list.add("Aditya"); // Adding object in arraylist
|
||||||
|
list.add("Misa");
|
||||||
|
list.add("Vidhi");
|
||||||
|
list.add("Suraj");
|
||||||
|
|
||||||
|
// Traversing list through Iterator
|
||||||
|
Iterator<String> itr = list.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
LinkedHashSet17a.class
Normal file
22
LinkedHashSet17a.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//17. write a java code to demonmstrate LinkedHashSet A
|
||||||
|
import java.util.*;
|
||||||
|
public class LinkedHashSet17a
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
LinkedHashSet<String> sweets = new LinkedHashSet<String>();
|
||||||
|
sweets.add("Kaju Katli");
|
||||||
|
sweets.add("Gulab Jamun");
|
||||||
|
sweets.add("Aflatoon");
|
||||||
|
sweets.add("Gajar Halwa");
|
||||||
|
sweets.add("Kaju Katli");
|
||||||
|
Iterator<String> itr = sweets.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BIN
LinkedHashSet17b.class
Normal file
20
LinkedHashSet17b.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//program 17b
|
||||||
|
import java.util.*;
|
||||||
|
public class LinkedHashSet17b
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
LinkedHashSet<String> sweets = new LinkedHashSet<String>();
|
||||||
|
sweets.add("Kaju Katli");
|
||||||
|
sweets.add("Gulab Jamun");
|
||||||
|
sweets.add("");
|
||||||
|
sweets.add("Gajar Halwa");
|
||||||
|
sweets.add("Kaju Katli");
|
||||||
|
Iterator<String> itr = sweets.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
LinkedHashSet17c.class
Normal file
20
LinkedHashSet17c.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//program 17c
|
||||||
|
import java.util.*;
|
||||||
|
public class LinkedHashSet17c
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
LinkedHashSet<String> sweets = new LinkedHashSet<String>();
|
||||||
|
sweets.add("Kaju Katli");
|
||||||
|
sweets.add("Gulab Jamun");
|
||||||
|
sweets.add("null");
|
||||||
|
sweets.add("Gajar Halwa");
|
||||||
|
sweets.add("Kaju Katli");
|
||||||
|
Iterator<String> itr = sweets.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
LinkedList13b.class
Normal file
18
LinkedList13b.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//program 13b
|
||||||
|
import java.util.*;
|
||||||
|
public class LinkedList13b
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
LinkedList<String> name1=new LinkedList<String>();
|
||||||
|
name1.add("Misa");
|
||||||
|
name1.add("Aditya");
|
||||||
|
name1.add("Aisha");
|
||||||
|
name1.add("Aditya");
|
||||||
|
Iterator<String> itr=name1.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
MovieBook.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//write a java program for inter thread communication using wait(), notify(), notifyall()
|
||||||
|
class TotalEarnings extends Thread
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
synchronized(this)
|
||||||
|
{
|
||||||
|
for(int i=1; i<=10; i++)
|
||||||
|
{
|
||||||
|
total=total+100;
|
||||||
|
}
|
||||||
|
this.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MovieBook
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
TotalEarnings te = new TotalEarnings();
|
||||||
|
te.start();
|
||||||
|
synchronized(te)
|
||||||
|
{
|
||||||
|
te.wait();
|
||||||
|
System.out.println("Total earnings: " +te.total);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Multi.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// write a java code by extending thread class
|
||||||
|
class Multi extends Thread
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
System.out.println("Thread is running...");
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Multi t1 = new Multi();
|
||||||
|
t1.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Multi3.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//write a java code by implementing runnable interface
|
||||||
|
public class Multi3 implements Runnable{
|
||||||
|
public void run(){
|
||||||
|
System.out.println("Thread is running...");
|
||||||
|
}
|
||||||
|
public static void main(String[] args){
|
||||||
|
Multi3 m1 = new Multi3();
|
||||||
|
Thread t1 = new Thread(m1);
|
||||||
|
t1.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
41
MultipleThread.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
//write a java program for Multiple thread acting on Single Object
|
||||||
|
public class MultipleThread implements Runnable
|
||||||
|
{
|
||||||
|
String task;
|
||||||
|
MultipleThread(String task)
|
||||||
|
{
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for(int i=1; i<=5; i++)
|
||||||
|
{
|
||||||
|
System.out.println(task+ ":" +i);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
catch(InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Thread nThread = Thread.currentThread();
|
||||||
|
System.out.println("Name of Thread: " +nThread);
|
||||||
|
|
||||||
|
MultipleThread mt = new MultipleThread("Hello Java");
|
||||||
|
Thread t1 = new Thread(mt);
|
||||||
|
Thread t2 = new Thread(mt);
|
||||||
|
Thread t3 = new Thread(mt);
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t3.start();
|
||||||
|
|
||||||
|
int count = Thread.activeCount();
|
||||||
|
System.out.println("No of active threads: " +count);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
MyThreadd.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// write a java code for two threads performing two tasks at a time
|
||||||
|
public class MyThreadd extends Thread
|
||||||
|
{
|
||||||
|
String task;
|
||||||
|
|
||||||
|
MyThreadd(String task)
|
||||||
|
{
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for(int i=1; i<=5; i++)
|
||||||
|
{
|
||||||
|
System.out.println(task+ ":" +i);
|
||||||
|
try{
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
catch(InterruptedException ie)
|
||||||
|
{
|
||||||
|
System.out.println(ie.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
MyThreadd th1 = new MyThreadd("Cut the ticket");
|
||||||
|
MyThreadd th2 = new MyThreadd("Show your seat number");
|
||||||
|
|
||||||
|
Thread t1 = new Thread(th1);
|
||||||
|
Thread t2 = new Thread(th2);
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
RunnableTest.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class x implements Runnable {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for(int i=0; i<=5; i++)
|
||||||
|
System.out.println("The Thread x is: " +i);
|
||||||
|
System.out.println("End of the Thread x");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class RunnableTest
|
||||||
|
{
|
||||||
|
public static void main (String[] args)
|
||||||
|
{
|
||||||
|
x r=new x();
|
||||||
|
Thread threadx=new Thread(r);
|
||||||
|
threadx.start();
|
||||||
|
System.out.println("The end of the main Thread");
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
SortingArray.class
Normal file
39
SortingArray.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//12 write a java program for sorting arrayList
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class SortingArray
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
ArrayList<String> StationList = new ArrayList<>();
|
||||||
|
|
||||||
|
StationList.add("Panvel");
|
||||||
|
StationList.add("Khandeshwar");
|
||||||
|
StationList.add("Mansarover");
|
||||||
|
StationList.add("Kharghar");
|
||||||
|
StationList.add("Belapur");
|
||||||
|
StationList.add("Seawoods");
|
||||||
|
StationList.add("Nerul");
|
||||||
|
StationList.add("Juinagar");
|
||||||
|
StationList.add("Sanpada");
|
||||||
|
StationList.add("Vashi");
|
||||||
|
StationList.add("Mankhurd");
|
||||||
|
|
||||||
|
System.out.println("Unsorted List: \n");
|
||||||
|
Iterator pre = StationList.iterator();
|
||||||
|
while(pre.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(pre.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(StationList);
|
||||||
|
System.out.println("\nSorted List: \n");
|
||||||
|
|
||||||
|
Iterator post = StationList.iterator();
|
||||||
|
while(post.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(post.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Stack15.class
Normal file
31
Stack15.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
//15. write a java code to demonstrate stack
|
||||||
|
import java.util.*;
|
||||||
|
public class Stack15
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Stack<String> food = new Stack<String>();
|
||||||
|
food.push("\nButter Chicken");
|
||||||
|
food.push("Dal Makhani");
|
||||||
|
food.push("Kadhai Paneer");
|
||||||
|
food.push("Prawns Koliwada");
|
||||||
|
food.push("Crab Soup");
|
||||||
|
Iterator<String> itr = food.iterator();
|
||||||
|
while(itr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(itr.next());
|
||||||
|
}
|
||||||
|
String Food = food.peek();
|
||||||
|
System.out.println("\nThe Top food item is: " +Food);
|
||||||
|
|
||||||
|
food.pop();
|
||||||
|
System.out.println("\nAfter Pop:");
|
||||||
|
Iterator<String> newItr = food.iterator();
|
||||||
|
while(newItr.hasNext())
|
||||||
|
{
|
||||||
|
System.out.println(newItr.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
17
TestMultiPriority1.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//write a java code for demonstrating thread priority
|
||||||
|
class TestMultiPriority1 extends Thread {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
System.out.println("Running thread name is: " +Thread.currentThread().getName());
|
||||||
|
System.out.println("Running thread priority is: "+Thread.currentThread().getPriority());
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
TestMultiPriority1 m1 = new TestMultiPriority1();
|
||||||
|
TestMultiPriority1 m2 = new TestMultiPriority1();
|
||||||
|
m1.setPriority(Thread.MIN_PRIORITY);
|
||||||
|
m2.setPriority(Thread.MAX_PRIORITY);
|
||||||
|
m1.start();
|
||||||
|
m2.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
72
TestSynchronization2.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
//Write a java program for demonstrating thread synchronization
|
||||||
|
class Table
|
||||||
|
{
|
||||||
|
synchronized void printTable(int n)
|
||||||
|
{
|
||||||
|
for(int i=1; i<=5; i++)
|
||||||
|
{
|
||||||
|
System.out.println(n*i);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(400);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyThread1 extends Thread
|
||||||
|
{
|
||||||
|
Table t;
|
||||||
|
MyThread1(Table t)
|
||||||
|
{
|
||||||
|
this.t = t;
|
||||||
|
}
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
t.printTable(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyThread2 extends Thread
|
||||||
|
{
|
||||||
|
Table t;
|
||||||
|
MyThread2(Table t)
|
||||||
|
{
|
||||||
|
this.t = t;
|
||||||
|
}
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
t.printTable(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestSynchronization2
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Table obj = new Table();
|
||||||
|
MyThread1 t1 = new MyThread1(obj);
|
||||||
|
MyThread2 t2 = new MyThread2(obj);
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
16
ThreadExample1.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
public class ThreadExample1 extends Thread
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
int a = 22;
|
||||||
|
int b = 26;
|
||||||
|
int result = a+b;
|
||||||
|
System.out.println("Thread started running..");
|
||||||
|
System.out.println("Sum of two numbers is: " +result);
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
ThreadExample1 t1 = new ThreadExample1();
|
||||||
|
t1.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
TreeSet18a.class
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
TreeSet18b.class
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Vector14a.class
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Vector14b.class
Normal file
24
Vector14b.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
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("Grocery at index 0: " + groceryList.get(0));
|
||||||
|
System.out.println("Grocery at index 1: " + groceryList.get(1));
|
||||||
|
System.out.println("Grocery at index 2: " + groceryList.get(2));
|
||||||
|
|
||||||
|
System.out.println("Items in Grocery list: ");
|
||||||
|
for(String item:groceryList)
|
||||||
|
{
|
||||||
|
System.out.println(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
groceryList.remove(groceryList.get(2));
|
||||||
|
System.out.println("Size of grocery after removal of Milk: " + groceryList.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
arrayList.class
Normal file
22
arrayList.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// 11. write a java program to demonstrate ArrayList
|
||||||
|
import java.util.ArrayList;
|
||||||
|
public class arrayList {
|
||||||
|
public static void main(String[] args){
|
||||||
|
ArrayList<String> catList = new ArrayList<>();
|
||||||
|
catList.add("Maine Coon");
|
||||||
|
catList.add("Ragdoll");
|
||||||
|
catList.add("Munchkin");
|
||||||
|
|
||||||
|
System.out.println("Cat Breed at index 0: " + catList.get(0));
|
||||||
|
System.out.println("Cat Breed index 1: " + catList.get(1));
|
||||||
|
System.out.println("Cat Breed index 2: " + catList.get(2));
|
||||||
|
|
||||||
|
System.out.println("Cat Breeds: ");
|
||||||
|
for(String cat: catList) {
|
||||||
|
System.out.println(cat);
|
||||||
|
}
|
||||||
|
|
||||||
|
catList.remove(catList.get(2));
|
||||||
|
System.out.println("Size of catList after removal of Ragdoll is: " + catList.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
linkedList.class
Normal file
25
linkedList.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//13. write a java program to demonstrate linked list
|
||||||
|
import java.util.LinkedList;
|
||||||
|
public class linkedList
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
LinkedList<String> StationList = new LinkedList<>();
|
||||||
|
|
||||||
|
StationList.add("Kharghar");
|
||||||
|
StationList.add("Belapur");
|
||||||
|
StationList.add("Nerul");
|
||||||
|
|
||||||
|
System.out.println("Station at Index 0: " +StationList.get(0));
|
||||||
|
System.out.println("Station at Index 1: " +StationList.get(1));
|
||||||
|
System.out.println("Station at Index 2: " +StationList.get(2));
|
||||||
|
|
||||||
|
System.out.println("Name of Stations in StationList:");
|
||||||
|
for(String Station: StationList)
|
||||||
|
{
|
||||||
|
System.out.println(Station);
|
||||||
|
}
|
||||||
|
StationList.remove("Belapur");
|
||||||
|
System.out.println("Size of StationList after removal: " +StationList.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
outputs/13b prog.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
outputs/14a prog.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
BIN
outputs/14b prog.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
outputs/15 prog.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
outputs/16 prog.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
outputs/17a prog.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
outputs/17b prog.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
outputs/17c prog.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
outputs/18a prog.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
outputs/18b prog.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
outputs/Area 9 b.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
outputs/Array list.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
outputs/Generic Class 9A .png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
outputs/Java Collection 10.png
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
BIN
outputs/Sorting array 12.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
outputs/program 12.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
outputs/program 13 linked list.png
Normal file
|
After Width: | Height: | Size: 21 KiB |