0% found this document useful (0 votes)
5 views140 pages

Oops

The document contains multiple Java class implementations demonstrating various programming concepts such as method overloading, inheritance, constructors, and string manipulation. It includes examples of classes like PhonePe, Box, and Student, showcasing their methods and interactions. Additionally, it highlights the use of static methods, final variables, and abstract classes in Java.

Uploaded by

Manoj Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views140 pages

Oops

The document contains multiple Java class implementations demonstrating various programming concepts such as method overloading, inheritance, constructors, and string manipulation. It includes examples of classes like PhonePe, Box, and Student, showcasing their methods and interactions. Additionally, it highlights the use of static methods, final variables, and abstract classes in Java.

Uploaded by

Manoj Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 140

OOPS:

=======================
class PhonePe
{
int mno=12345678;

int pin=1234;

void TM()
{
System.out.println("money is transferred
successfully.....");
}

void CB()
{
System.out.println("no money in the back first
deposit....");
}
}

class Sample
{
public static void main(String args[])
{
PhonePe p=new PhonePe();

System.out.println(p.mno);

p.TM();

}
}
class Box
{
int l=5,b=10,h=20;

void area()
{
System.out.println("Area : "+l*b);
}

void volume()
{
System.out.println("Volume : "+l*b*h);
}
}

class Sample2
{
public static void main(String args[])
{
Box b1=new Box();

System.out.println(b1.l+"\t"+b1.b+"\t"+b1.h);

b1.volume();

b1.area();

}
}
class A
{
void add(int a, int b)
{
System.out.println("sum : "+(a+b));
}

void login(int mno,int pin)


{
if(mno==1234 && pin==1234)
System.out.println("login success");
else
System.out.println("login failed");
}

void isEmployed(Boolean b)
{
if(b==true)
System.out.println("U r employeed");
else
System.out.println("U R Unemployed");
}

void TM(int facc, int tacc, int amount)


{
System.out.println(amount+" rs is transferred from
"+facc+" to "+tacc);
}
}

class Sample
{
public static void main(String args[])
{
A a=new A();

a.add(10,5);
a.login(1234,5678);
a.TM(101,102,500);
a.isEmployed(false);
}
}
class A
{
int add(int a,int b)
{
int sum=a+b;

return sum;
}

boolean login(int mno)


{
if(mno==1234)
return true;
else
return false;
}

String course()
{
return "JFS";
}
}
class Sample
{
public static void main(String args[])
{
A a=new A();

int x =a.add(10,5);

boolean y =a.login(1234);

String z =a.course();

System.out.println(x+"\t"+y+"\t"+z);

}
}
class A
{
int x=100;

public void display()


{
int y=200;

System.out.println(x);
System.out.println(y);
}
}

class Sample
{
public static void main(String args[])
{
A obj=new A();

obj.display();
}
}
class A
{
int x=100;

public void show()


{
System.out.println("show method executed");
}
}
class B extends A
{
public void display()
{
System.out.println("display method executed");
}
}

class Sample
{
public static void main(String args[])
{
A obj1=new A();

System.out.println(obj1.x); // 100
obj1.show();

B obj2=new B();
obj2.display();
obj2.show();
System.out.println(obj2.x);

}
}
class A
{
public void show()
{
System.out.println("show method executed");
}
}

class B extends A
{
public void display()
{
System.out.println("display method executed");
}
}

class C extends A
{
public void demo()
{
System.out.println("demo method executed");
}
}

class Sample
{
public static void main(String args[])
{
A a=new A();
a.show();

B b=new B();
b.show();
b.display();

C c=new C();
c.show();
c.demo();

}
}
class A
{
public void show()
{
System.out.println("show method executed");
}
}

class B extends A
{
public void display()
{
System.out.println("display method executed");
}
}

class C extends B
{
public void demo()
{
System.out.println("demo method executed");
}
}

class Sample
{
public static void main(String args[])
{
A a=new A();
a.show();

B b=new B();
b.show();
b.display();

C c=new C();
c.show();
c.display();
c.demo();

}
}
class A
{
public void SayHiii()
{
System.out.println("Welcome sir.....");
}

public void SayHiii(String cname)


{
System.out.println("Welcome "+cname+" sir.....");
}

public void SayHiii(int amount)


{
System.out.println("Tq for the tip "+amount);
}

public void SayHiii(String cname,int amount)


{
System.out.println("Welcome "+cname+" sir... Tq for the
tip.."+amount);
}

public void SayHiii(int amount,String cname)


{
System.out.println(cname+"\t"+amount);
}
}

class Sample
{
public static void main(String args[])
{
A obj=new A();

obj.SayHiii();
obj.SayHiii("pavan");
obj.SayHiii(500);
obj.SayHiii("pavan",500);
obj.SayHiii(500,"pavan");

}
}
class A
{
public void show()
{
System.out.println("class A show method executed");
}
}

class B extends A
{

public void show()


{
System.out.println("class B show method executed");
}

class Sample
{
public static void main(String args[])
{
A obj1=new A();
obj1.show();

B obj2=new B();
obj2.show();

}
}

class A
{
public void show()
{
System.out.println("class A show method executed");
}
}

class B extends A
{

public void show()


{
System.out.println("class B show method executed");
}

class Sample
{
public static void main(String args[])
{
A obj;

obj =new A();


obj.show();

obj =new B();


obj.show();

}
}
class Student
{
int sid;

String sname;

int sfee;

String scourse;

public Student()
{
sid=101;
sname="pavan";
sfee=50000;
scourse="Java";
System.out.println("constructor executed");
}

public void display()


{

System.out.println(sid+"\t"+sname+"\t"+sfee+"\t"+scourse);
}

class Sample
{
public static void main(String args[])
{
new Student().display();

}
}

class Box
{
int l,b,h;

public Box()
{
l=1; b=1; h=1;
System.out.println("constructor executed....");
}
public void volume()
{
int v=l*b*h;
System.out.println("volume v : "+v);
}
}

class Sample
{
public static void main(String args[])
{
Box b1 =new Box();

b1.volume();

}
}

class Box
{
int l,b,h;

public Box(int x,int y, int z)


{
l=x; b=y; h=z;
System.out.println("constructor executed");
}
public void volume()
{
int v=l*b*h;
System.out.println("volume v : "+v);
}
}
class Sample
{
public static void main(String args[])
{
Box b1 =new Box(5,10,20);
b1.volume();
}
}

class Box
{
int l,b,h;

public Box()
{
l=1;b=1;h=1;
}
public Box(int x)
{
l=x; b=x; h=x;
}

public Box(int x, int y)


{
l=x; b=x; h=y;
}

public Box(int x, int y ,int z)


{
l=x; b=y; h=z;
}

public void volume()


{
int v=l*b*h;
System.out.println("volume v : "+v);
}

class Sample
{
public static void main(String args[])
{
Box b1 =new Box();
b1.volume();

Box b2 =new Box(5);


b2.volume();

Box b3 =new Box(5,10);


b3.volume();

Box b4 =new Box(5,10,20);


b4.volume();

}
}
class B
{
int x=1000;
}
class A extends B
{
int x=100;

public void display(int x)


{
System.out.println(x);
System.out.println(this.x);
System.out.println(super.x);
}
}

class Sample
{
public static void main(String args[])
{
A obj=new A();

obj.display(10);

}
}

class A
{
public void show()
{
System.out.println("class A show method executed...");
}
}

class B extends A
{
public void show()
{
System.out.println("class B show method
executed..");
}

public void execute()


{
show();
this.show();
super.show();
}

}
class Sample
{
public static void main(String args[])
{
B obj=new B();
obj.execute();
}
}

class Box
{
int l,b,h;

public Box()
{
l=1; b=1;h=1;
System.out.println("default constructor executed.....");
}

public Box( int x, int y, int z)


{
l=x; b=y; h=z;
System.out.println("paremeterized constructor
executed.....");
}

public void volume()


{
int v=l*b*h;
System.out.println("volume v : "+v);
}
}
class Cube extends Box
{
public Cube()
{
// super();
super(5,5,5);
}

class Sample
{
public static void main(String args[])
{
new Cube().volume();
}
}
class Sample
{
public static void main(String args[])
{
String x="Pavan Kalyan";

String y =x.toUpperCase();

System.out.println(x); //Pavan Kalyan


System.out.println(y); // PAVAN KALYAN
}
}
class Sample
{
public static void main(String args[])
{
String x="Pavan Kalyan";

System.out.println(x.length()); // 12
System.out.println(x.toUpperCase()); // PAVAN KALYAN
System.out.println(x.toLowerCase()); // pavan kalyan
System.out.println(x.charAt(7)); // a
System.out.println(x.equals("krishna")); // flase
System.out.println(x.equalsIgnoreCase("PAVAN KALYAN"));
// true
System.out.println(x.substring(0,6)); // Pavan
System.out.println(x.substring(7)); // kalyan

System.out.println(x); //Pavan Kalayn

}
}
class Sample
{
public static void main(String args[])
{
StringBuffer x=new StringBuffer("pavan");

System.out.println(x); // pavan

x.insert(1,"xyz");
System.out.println(x); // pxyzavan

x.delete(1,4);
System.out.println(x); // pavan

x.append("kalyan");
System.out.println(x); // pavankalyan
x.reverse();
System.out.println(x); //

System.out.println(x.length()); // 11

}
}
class Sample
{
public static void main(String args[])
{
String x=new String("pavan");
String y=new String("pavan");

System.out.println(x==y); // false
System.out.println(x.equals(y)); // true

}
}
class Sample
{
public static void main(String args[])
{
String x=new String("pavan");
String y=new String("pavan");

System.out.println(x==y); // false
System.out.println(x.equals(y)); // true

StringBuffer a=new StringBuffer("pavan");


StringBuffer b=new StringBuffer("pavan");

System.out.println(a==b); // false
System.out.println(a.equals(b)); // false
}
}
class Sample
{
public static void main(String args[])
{
String x="pavan";
String y=new String("pavan");
String a=new String("pavan");
String b="pavan";

System.out.println(x==y); // false
System.out.println(x==a); // false
System.out.println(x==b); // true
System.out.println(y==a); // false
System.out.println(y==b); // false
System.out.println(a==b); // false
}
}
class Sample
{
public static void main(String args[])
{
String x=new String("pavan");
String y=new String("kalyan");

x=y;
System.out.println(x); // kalyan
System.out.println(y); // kalyan

System.out.println(x==y); // true

}
}
class Sample
{
public static void main(String args[])
{

String x="pavan";
String y=new String("pavan");
String a=new String("pavan");
String b="pavan";

y=b;

System.out.println(x==y); // true
System.out.println(x==a); // false
System.out.println(x==b); // true
System.out.println(y==a); // false
System.out.println(y==b); // true
System.out.println(a==b); // false
}
}
class Sample
{
public static void main(String args[])
{

String x="pavan";
String y="kalyan";
String z="pavankalyan";

String a=x.concat(y);

System.out.println(a==z); // false
}
}
import teks.Student;
class Sample
{
public static void main(String args[])
{

Student s=new Student();


s.result();

}
}
class Student
{
public int sid=100;
public static String clgName="Teks";

public void result()


{
System.out.println("verify website"+clgName +"\t"+sid);
}

public static void list()


{
System.out.println("java");
}

public class Sample


{
static
{
System.out.println("static block executed");
}

public static void main(String args[])


{
System.out.println(Student.clgName);
Student.list();

Student s=new Student();

System.out.println(s.sid);
s.result();

}
}
class Student
{
public final int sid=100;

public void demo()


{
System.out.println(sid); // 100

sid=200;

System.out.println(sid); // 200

}
}

class Sample
{
public static void main(String args[])
{
Student s=new Student();

s.demo();

}
}

final class A
{
public void demo()
{
System.out.println("class A demo method executed");
}
}

class B extends A
{
public void demo()
{
System.out.println("class B demo method executed");
}

class Sample
{
public static void main(String args[])
{
B obj=new B();

obj.demo();
}
}
abstract class Bank
{
public abstract void apply();

public abstract void CB();

public void TM()


{
System.out.println("money transferred
successfully.....");
}
}

class SBI extends Bank


{

public void apply()


{
System.out.println("applied successfully.....");
}

public void CB()


{
System.out.println("This is your bank balance");
}
}

class Sample
{
public static void main(String args[])
{
SBI s=new SBI();
s.apply();
s.CB();
s.TM();
}
}

abstract class Bank


{
public abstract void apply();

public abstract void CB();

public abstract void TM();

abstract class SBI extends Bank


{

public void TM()


{
System.out.println("money transferred
successfully.....");
}
public void CB()
{
System.out.println("This is your bank balance");
}

class SBI2 extends SBI


{

public void apply()


{
System.out.println("applied successfully.....");
}

class Sample
{
public static void main(String args[])
{
SBI2 s=new SBI2();
s.apply();
s.CB();
s.TM();
}
}
interface Bank
{
void apply();
void CB();

void TM();

class SBI implements Bank


{
public void TM()
{
System.out.println("money transferred
successfully.....");
}

public void apply()


{
System.out.println("applied successfully.....");
}

public void CB()


{
System.out.println("This is your bank balance");
}
}

class Sample
{
public static void main(String args[])
{
SBI s=new SBI();

s.apply();
s.TM();
s.CB();

}
}

interface A
{
public void display();

public void demo();


}

interface B extends A
{
public void hello();
}

class C implements B
{
public void display()
{
System.out.println("display method executed");
}

public void demo()


{
System.out.println("demo method executed");
}

public void hello()


{
System.out.println("hello method executed");
}

class Sample
{
public static void main(String args[])
{
C obj=new C();

obj.demo();
obj.display();
obj.hello();
}
}
interface A
{
public void show();
}

interface B
{
public void show();
}

class C implements A,B


{
public void show()
{
System.out.println("class C show method executed");
}
}

class Sample
{
public static void main(String args[])
{
C obj=new C();

obj.show();
}
}
class Sample
{
public static void main(String args[])
{

boolean x1=false;
int y1=100;
double z1=10.567;

Boolean x2=new Boolean(x1);


Integer y2=new Integer(y1);
Double z2=new Double(z1);

System.out.println("auto boxing is completed");

boolean x3=x2;
int y3=y2;
double z3=z2;

System.out.println("auto unboxing is completed");


}
}

class Sample
{
public static void main(String args[])
{
String x="10";
String y="20";

System.out.println(x+y);

int a =Integer.parseInt(x);
int b =Integer.parseInt(y);
System.out.println(a+b);

System.out.println(Integer.parseInt(x)+Integer.parseInt(y));

}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter first no?");


int a =sc.nextInt();

System.out.println("Enter second no ?");


int b =sc.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
System.out.println(a%b);

}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{

Scanner sc1=new Scanner(System.in);


Scanner sc2=new Scanner(System.in);

System.out.println("Enter your salary ?");


double salary =sc1.nextDouble();

System.out.println("Enter your age ?");


int age =sc1.nextInt();

System.out.println("Are you married ?");


boolean isMarried =sc1.nextBoolean();

System.out.println("Enter your name ?");


String name =sc2.nextLine();
System.out.println(name+"\t"+age+"\t"+salary+"\t"+isMarried);
}
}

InputMistmatchException,ArithmeticException

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{

Scanner sc=new Scanner(System.in);

System.out.println("Enter first no ?");


int a=sc.nextInt();

System.out.println("Enter second no?");


int b=sc.nextInt();

int c=a/b;
System.out.println("Quotient is : "+c);
System.out.println("application completed
execution....");
}
}

NullPointerException:
import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
String x=null;

System.out.println("No of characters is : "+x.length());

System.out.println("application completed
execution....");
}
}

ArrayIndexOutOfBoundsException
import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
String x[]={"a","b","c","d","e"};
int l= x.length;
System.out.println("size : "+l);

for(int i=0;i<=l;i++)
{
System.out.println(x[i]);
}

System.out.println("application completed
execution....");
}
}
import java.util.Scanner;
class Sample
{
public static void main(String args[])
{

Scanner sc=new Scanner(System.in);

System.out.println("Enter first no ?");


int a=sc.nextInt();
System.out.println("Enter second no?");
int b=sc.nextInt();

try
{
int c=a/b;
System.out.println("Quotient is : "+c);
}
catch(ArithmeticException e)
{
System.out.println("division with 0 not
possible.....");
}

System.out.println("application completed
execution....");

}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
String x=null;

try
{
System.out.println("No of characters is :
"+x.length());
}
catch(NullPointerException e)
{
System.out.println("The value of string is null");
}

System.out.println("application completed
execution....");

}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
String x[]={"a","b","c","d","e"};

int l= x.length;
System.out.println("size : "+l);

try
{
for(int i=0;i<=l;i++)
{
System.out.println(x[i]);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("invalid index");
}

System.out.println("application completed
execution....");

}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter first no ?");


int a=sc.nextInt();

System.out.println("Enter second no?");


int b=sc.nextInt();

String x=null;

try
{
int c=a/b;
System.out.println("Quotient is : "+c);

int l=x.length();
System.out.println("no of characters is : "+l);
}
catch(ArithmeticException e)
{
System.out.println("Division with 0 not
possible....");
}

catch(NullPointerException e)
{
System.out.println("string x value is null");
}

System.out.println("application completed
execution....");
}
}
import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter first no ?");


int a=sc.nextInt();

System.out.println("Enter second no?");


int b=sc.nextInt();

String x=null;

try
{
int c=a/b;
System.out.println("Quotient is : "+c);

int l=x.length();
System.out.println("no of characters is : "+l);
}

catch(ArithmeticException e)
{
System.out.println("division with 0 not
possible....");
}

catch(NullPointerException e)
{
System.out.println("null pointer exception
occured");
}

catch(Exception e)
{
System.out.println(e);
System.out.println("exception occured");
}

System.out.println("application completed
execution....");
}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter first no ?");


int a=sc.nextInt();
System.out.println("Enter second no?");
int b=sc.nextInt();

String x=null;

try
{
int c=a/b;
System.out.println("Quotient is : "+c);
}
catch(ArithmeticException e)
{
System.out.println("Division with 0 not
possible......");
}

try
{
int l=x.length();
System.out.println("No of characters is : "+l);
}
catch(NullPointerException e)
{
System.out.println("string x value is null");
}

System.out.println("application completed
execution....");
}
}
import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter first no ?");


int a=sc.nextInt();

System.out.println("Enter second no?");


int b=sc.nextInt();

try
{
int c=a/b;
System.out.println("Quotient is : "+c);
}
catch(ArithmeticException e)
{
System.out.println("Division with 0 not
possible......");
}

finally
{
System.out.println("Finalyy block of code
executed.......");
}

System.out.println("application completed
execution....");
}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[]) throws
InterruptedException
{
System.out.println("application started execution...");

System.out.println("stop for 1st time");


Thread.sleep(5000);

System.out.println("stop for 2nd time");


Thread.sleep(5000);

System.out.println("stop for 3rd time");


Thread.sleep(5000);
System.out.println("application completed
execution....");
}
}

import java.util.Scanner;
class Sample
{
public static void main(String args[])
{
System.out.println("application started execution...");

Scanner sc=new Scanner(System.in);

System.out.println("Enter your age...");


int age=sc.nextInt();

if(age<18)
{
throw new ArithmeticException("u r not
eligilble....");
}
else
{
System.out.println("U r eligible continue.....");
}
System.out.println("application completed
execution....");
}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
ArrayList l =new ArrayList();

System.out.println(l.size()); // 0
System.out.println(l.isEmpty()); // true
System.out.println(l); // []

l.add("a");
l.add(false);
l.add(100);
l.add(10.345);
l.add(false);
l.add("b");
l.add("c");
l.add(null);

System.out.println(l); // [a false 100 10.345 false b


c null ]
l.add(1, "z");
System.out.println(l); // [a z false 100 10.345 false
b c null ]

l.remove("z");
l.remove("c");
System.out.println(l); // [a false 100 10.345 false b
null ]

l.remove(5);
System.out.println(l); // [a false 100 10.345 false c
null ]

l.remove(false);
System.out.println(l); // [a 100 10.345 false c null
]

// l.remove(100);
// System.out.println(l); // [a 10.345 false c null
]

System.out.println(l.get(0)); // a

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
Vector v=new Vector();

v.addElement("a");
v.addElement(false);
v.addElement(100);
v.addElement(null);
v.addElement(false);

System.out.println(v); // a false 100 null false

v.removeElement(false);
System.out.println(v); // a 100 null false

System.out.println(v.get(0)); // a

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
LinkedList l=new LinkedList();

l.add("a");
l.add("b");
l.add("c");

l.add(100);
l.add(false);
l.add(null);
l.add(false);

l.add("x");
l.add("y");
l.add("z");
System.out.println(l); // a b c 100 false null
false x y z

l.add(3,200);
System.out.println(l); // a b c 200 100 false null
false x y z

l.addFirst("A");
l.addLast("Z");
System.out.println(l); // A a b c 200 100 false
null false x y z Z

System.out.println(l.getFirst()); // A
System.out.println(l.getLast()); // Z

l.removeFirst();
l.removeLast();
System.out.println(l); // a b c 200 100 false null
false x y z

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
Stack s=new Stack();

s.add("a");
s.add(false);
s.add(100);
s.add(null);
s.add(false);

System.out.println(s); // a false 100 null false

s.remove("a");
System.out.println(s); // false 100 null false

s.remove(1);
System.out.println(s); // false null false

System.out.println(s.get(1)); // null

s.push("a");
s.push("b");
System.out.println(s); // false null false a b

System.out.println(s.pop()); // b

System.out.println(s); // false null false a

System.out.println(s.peek()); // a
System.out.println(s); // false null false a
}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
HashSet h=new HashSet();

h.add("a");
h.add("b");
h.add(false);
h.add(null);

h.add(false);

System.out.println(h);

System.out.println(h.contains(false));

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
LinkedHashSet h=new LinkedHashSet();

h.add("a");
h.add("b");
h.add(false);
h.add(null);

h.add(false);

System.out.println(h);

System.out.println(h.contains(false));

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
TreeSet t=new TreeSet();

t.add(100);
t.add(90);
t.add(80);
t.add(110);
t.add(85);
t.add(95);
t.add(105);
t.add(115);

System.out.println(t); // 80 85 90 95 100 105 110


115

}
}

import java.util.*;
class Sample
{
public static void main(String args[])
{
TreeSet t=new TreeSet();

t.add("pavan");
t.add("kalyan");
t.add("krishna");
t.add("Karthik");
t.add("Rajesh");
t.add("ram");
t.add("Parthiban");
t.add("Deepika");
t.add("ajay");
t.add("dinesh");
t.add("x");

System.out.println(t); // 80 85 90 95 100 105 110


115

}
}

import java.util.*;
class Sample
{
public static void main(String args[])
{
TreeSet t=new TreeSet();

t.add(true);
t.add(false);
System.out.println(t); //

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
HashMap h=new HashMap();

h.put(101,"pavan");
h.put(false,false);
h.put("a",50000);

System.out.println(h);

h.put(false,"xyz");
System.out.println(h);

h.put("b","pavan");
System.out.println(h);

h.put(null,null);
System.out.println(h);

}
}

import java.util.*;
class Sample
{
public static void main(String args[])
{
LinkedHashMap h=new LinkedHashMap();

h.put(101,"pavan");
h.put(false,false);
h.put("a",50000);

System.out.println(h);

h.put(false,"xyz");
System.out.println(h);

h.put("b","pavan");
System.out.println(h);

h.put(null,null);
System.out.println(h);

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
TreeMap t=new TreeMap();

t.put(100,null);
t.put(90,"a");
t.put(95,false);
t.put(105,50000);
t.put(120,false);

System.out.println(t);

t.put(100,"xyz");
System.out.println(t);

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
Vector v=new Vector();

v.add("a");
v.add("b");
v.add("c");
v.add("d");
v.add("e");
v.add("f");
System.out.println(v); // a b c d e f

Enumeration e =v.elements();

while(e.hasMoreElements())
{
System.out.println(e.nextElement());
}

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
Vector v=new Vector();

v.add("a");
v.add("b");
v.add("c");
v.add("d");
v.add("e");
v.add("f");
System.out.println(v); // a b c d e f

Iterator i =v.iterator();

while(i.hasNext())
{
System.out.println(i.next());
}

i.remove();
System.out.println(v); // a b c d e f g

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
Vector v=new Vector();
v.add("a");
v.add("b");
v.add("c");
v.add("d");
v.add("e");
v.add("f");
System.out.println(v); // a b c d e f

ListIterator li =v.listIterator();

while(li.hasNext())
{
System.out.println(li.next());
}

li.remove();
li.add("h");
System.out.println(v); // a b c d e h

while(li.hasPrevious())
{
System.out.println(li.previous());
}

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
ArrayList l=new ArrayList();

l.add(90);
l.add(70);
l.add(100);
l.add(60);
l.add(120);

System.out.println(l); // 90 70 100 60 120

Collections.sort(l);
System.out.println(l); // 60 70 90 100 120

System.out.println(Collections.binarySearch(l,90));
// 2
System.out.println(Collections.binarySearch(l,70));
// 1
System.out.println(Collections.binarySearch(l,95));
// -4
System.out.println(Collections.binarySearch(l,105));
// -5

}
}
import java.util.*;
class Sample
{
public static void main(String args[])
{
ArrayList<Integer> l=new ArrayList<Integer>();

l.add(101);
l.add(102);
l.add(103);
l.add(104);
l.add(105);
// l.add("pavan");
System.out.println(l); // 101 102 103 104 105

int s1=l.get(0);
int s2=l.get(1);
int s3=l.get(2);
int s4=l.get(3);
int s5=l.get(4);

System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println(s4);
System.out.println(s5);
}
}

You might also like