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

JPR Manual Answers Experiment 4

The document contains two Java programs demonstrating the use of the String and StringBuffer classes. The first program showcases various String methods such as length, case conversion, and substring. The second program illustrates StringBuffer methods including append, insert, replace, delete, and reverse, along with displaying its capacity and length.

Uploaded by

Riya Patil
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)
10 views3 pages

JPR Manual Answers Experiment 4

The document contains two Java programs demonstrating the use of the String and StringBuffer classes. The first program showcases various String methods such as length, case conversion, and substring. The second program illustrates StringBuffer methods including append, insert, replace, delete, and reverse, along with displaying its capacity and length.

Uploaded by

Riya Patil
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/ 3

Experiment No:-4

1. Write a program to show the use of all methods of String class.


Code:
class Main
{
public static void main(String args[])
{
String s="Sy";
String s1="Welcome to JPR";
System.out.println(s);
System.out.println(s1);
System.out.println(s1.length());
System.out.println(s1.toUpperCase());
System.out.println(s.toLowerCase());
System.out.println(s1.startsWith("W"));
System.out.println(s.endsWith("z"));
System.out.println(s1.charAt(2));
System.out.println(s1.substring(1,5));
System.out.println(s1.concat(s));
}
}
Output:
2. Write a program to implement all methods of StringBuffer class.
Code:
class Main
{
public static void main(String[] args)
{
StringBuffer sb = new StringBuffer("Hello");
sb.append(" World!");
System.out.println("After append: " + sb);

sb.insert(5, " Java");


System.out.println("After insert: " + sb);

sb.replace(6, 10, "C++");


System.out.println("After replace: " + sb);

sb.delete(6, 10);
System.out.println("After delete: " + sb);

sb.reverse();
System.out.println("After reverse: " + sb);
System.out.println("Capacity: " + sb.capacity());
System.out.println("Length: " + sb.length());
}
}
Output:

You might also like