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

PR 4

The document provides a Java program that demonstrates various methods of the String and StringBuffer classes. It includes operations such as finding length, character at a specific index, concatenation, case conversion, substring extraction, character replacement, and string manipulation using StringBuffer methods like append, insert, delete, and reverse. The output of the program illustrates the results of these operations.
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)
9 views2 pages

PR 4

The document provides a Java program that demonstrates various methods of the String and StringBuffer classes. It includes operations such as finding length, character at a specific index, concatenation, case conversion, substring extraction, character replacement, and string manipulation using StringBuffer methods like append, insert, delete, and reverse. The output of the program illustrates the results of these operations.
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/ 2

Practical no 4 : Write a program for implementation of different methods

of String class , String buffer class


Public class StringDemo {

Public static void main(String[] args) {


String s = “Hello”;
System.out.println(s.length());
System.out.println(s.charAt(1));
System.out.println(s.concat(“ World”));
System.out.println(s.toUpperCase());

System.out.println(s.toLowerCase());
System.out.println(s.substring(1, 4));
System.out.println(s.replace(‘l’, ‘p’));
System.out.println(s.indexOf(‘o’));
System.out.println(s.startsWith(“He”));

System.out.println(s.endsWith(“lo”));
StringBuffer sb = new StringBuffer(“Hello”);
System.out.println(sb.append(“ World”));
System.out.println(sb.insert(5, “ Java”));
System.out.println(sb.delete(5, 10));
System.out.println(sb.replace(6, 11, “Python”));

System.out.println(sb.reverse());
System.out.println(sb.reverse());
}. }
Output :-
5
E
Hello World

HELLO
Hello
Ell
Heppo
4

True
True
Hello World
Hello Java World
Hello World
Hello Python World

dlroW nohtyP olleH


Hello Python World

You might also like