[go: up one dir, main page]

0% found this document useful (0 votes)
4 views2 pages

Practical 4

The document contains two Java classes demonstrating string manipulation and the use of StringBuffer. The first class performs various string operations such as length, character access, comparison, and case conversion. The second class showcases the creation and modification of a StringBuffer, including appending and inserting characters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Practical 4

The document contains two Java classes demonstrating string manipulation and the use of StringBuffer. The first class performs various string operations such as length, character access, comparison, and case conversion. The second class showcases the creation and modification of a StringBuffer, including appending and inserting characters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

class str

public static void main(String args[])

String s1="Java";

String s2="Hello";

int len=s1.length();

System.out.println("Length of string:"+len);

char at=s1.charAt(2);

System.out.println("Character at index 2:"+at);

int com=s1.compareTo(s2);

System.out.println("Both strings are compared:"+com);

boolean b=s1.equals(s2);

System.out.println("Both strings are compared using equals method:"+b);

boolean b1=s1.equalsIgnoreCase(s2);

System.out.println("Both string are compared using equalsIgnoresTo method"+b1);

System.out.println("Character replaced string="+s1.replace('J','P'));

boolean b2=s1.startsWith("J");

System.out.println("String starts with="+b2);

boolean b3=s2.endsWith("a");

System.out.println("Whether String ends with a:"+b3);

int i2=s1.lastIndexOf('j','a');

System.out.println("last index="+i2);

System.out.println("String into upper case="+s2.toUpperCase());

System.out.println("String into Lower case="+s2.toLowerCase());

System.out.println("String concatination="+s1.concat(s2));

boolean b4=s1.contains("JA");

System.out.println("contain method="+b4);

}
class IsStringBuff

public static void main(String[] args) {

StringBuffer b = new StringBuffer();

b.append("hello");

System.out.println("Capacity: " + b.capacity());

b.setCharAt(0, 'H');

b.insert(5, " world");

System.out.println("Final StringBuffer: " + b);

You might also like