0% found this document useful (0 votes)
3 views3 pages

Java Programs Full

The document contains three Java programs demonstrating various collection and string manipulation methods. The first program showcases operations on ArrayLists, TreeSets, Queues, Deques, and HashMaps. The second program focuses on string methods such as length, character access, comparison, and substring operations, while the third program illustrates the use of StringBuffer for string manipulation, including appending, inserting, and deleting characters.

Uploaded by

money2005qw
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)
3 views3 pages

Java Programs Full

The document contains three Java programs demonstrating various collection and string manipulation methods. The first program showcases operations on ArrayLists, TreeSets, Queues, Deques, and HashMaps. The second program focuses on string methods such as length, character access, comparison, and substring operations, while the third program illustrates the use of StringBuffer for string manipulation, including appending, inserting, and deleting characters.

Uploaded by

money2005qw
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

1.

Full Collection Methods Program


import [Link].*;

public class FullMethodsDemo {


public static void main(String[] args) {

ArrayList<Integer> list1 = new ArrayList<>();


ArrayList<Integer> list2 = new ArrayList<>();

[Link](10);
[Link](20);
[Link](30);

[Link](20);
[Link](40);

[Link]("List1: " + list1);


[Link]("List2: " + list2);

[Link](list2);
[Link]([Link](20));
[Link](list2);

[Link](50);
[Link](60);
[Link]([Link](50));

[Link]("Contains: " + [Link](50));


[Link]("Size: " + [Link]());

[Link](0, 999);
[Link]("Get: " + [Link](0));

Iterator<Integer> it = [Link]();
while([Link]()) {
[Link]([Link]()+" ");
}

[Link]();

TreeSet<Integer> set = new TreeSet<>();


[Link](10);
[Link](20);
[Link](30);
[Link](40);

[Link]([Link](30));
[Link]([Link](20));
[Link]([Link](20,40));
[Link]([Link](30));
[Link]([Link](30));
[Link]([Link]());
[Link]([Link]());

Queue<Integer> q = new PriorityQueue<>();


[Link](10);
[Link](20);
[Link](30);

[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());

Deque<Integer> dq = new ArrayDeque<>();


[Link](10);
[Link](20);

[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());

HashMap<String,Integer> map = new HashMap<>();


[Link]("A",100);
[Link]("B",200);
[Link]("C",300);

[Link]([Link]("A"));
[Link]([Link]("B"));
[Link]([Link](300));

for([Link]<String,Integer> e: [Link]()){
[Link]([Link]()+"="+[Link]());
}

[Link]();
}
}

2. Full String Methods Program


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

String s = "Hello World";


String s1 = "Hello";
String s2 = "hello";

[Link]("Length: " + [Link]());


[Link]("charAt: " + [Link](1));

char ch[] = new char[5];


[Link](0,5,ch,0);
[Link]("getChars: " + new String(ch));

[Link]("getBytes: " + [Link]([Link]()));

[Link]("toCharArray: " + [Link]()[2]);

[Link]("equals: " + [Link](s2));


[Link]("equalsIgnoreCase: " + [Link](s2));

[Link]("regionMatches: " + [Link](0,s2,0,3));

[Link]("startsWith: " + [Link]("Hello"));


[Link]("endsWith: " + [Link]("World"));

[Link]("compareTo: " + [Link](s2));

String s3 = new String("Hello");


[Link]("== : " + (s1==s3));
[Link]("equals: " + [Link](s3));

[Link]("indexOf: " + [Link]("o"));


[Link]("lastIndexOf: " + [Link]("o"));

[Link]("substring: " + [Link](6));


[Link]("concat: " + [Link](" Java"));
[Link]("replace: " + [Link]('o','x'));
[Link]("trim: " + " Hi ".trim());

int n = 10;
[Link]("valueOf: " + [Link](n));

[Link]("lower: " + [Link]());


[Link]("upper: " + [Link]());
}
}

3. Full StringBuffer Methods Program


public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Hello");

[Link]("Length: " + [Link]());


[Link]("Capacity: " + [Link]());

[Link](50);
[Link](10);

sb = new StringBuffer("Hello");

[Link]("charAt: " + [Link](1));


[Link](0,'J');

[Link](" World");
[Link](5," Java");
[Link]();

sb = new StringBuffer("Hello World");

[Link](5,11);
[Link](1);

sb = new StringBuffer("Hello World");


[Link](6,11,"Java");

[Link]([Link](6,10));
[Link]([Link]());
}
}

You might also like