0% found this document useful (0 votes)
14 views

Kalpesh 6

The document discusses two Java programs, the first implements string functions like length, uppercase, lowercase, substring, indexOf, replace, trim, startsWith, and endsWith. The second program implements string buffer functions like append, insert, delete, setCharAt, length, and reverse.

Uploaded by

KALPESH BORSE
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)
14 views

Kalpesh 6

The document discusses two Java programs, the first implements string functions like length, uppercase, lowercase, substring, indexOf, replace, trim, startsWith, and endsWith. The second program implements string buffer functions like append, insert, delete, setCharAt, length, and reverse.

Uploaded by

KALPESH BORSE
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

JAVA PRACTICAL 2106025

Program 1:-Program for implementing String functions :-

public class string_functions {


public static void main(String[] args) { //2106025
String text = "Hello, World!";

int length = text.length();


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

String uppercase = text.toUpperCase();


String lowercase = text.toLowerCase();
System.out.println("Uppercase: " + uppercase);
System.out.println("Lowercase: " + lowercase);

String substring = text.substring(7);


System.out.println("Substring from index 7: " + substring);

int indexOfComma = text.indexOf(",");


System.out.println("Index of comma: " + indexOfComma);

String replaced = text.replace("World", "Universe");


System.out.println("Replaced: " + replaced);

String paddedText = " Some text with spaces ";


String trimmedText = paddedText.trim();
System.out.println("Trimmed text: " + trimmedText);

boolean startsWithHello = text.startsWith("kkHello");


boolean endsWithWorld = text.endsWith("World!");
System.out.println("Starts with 'Hello': " + startsWithHello);
System.out.println("Ends with 'World!': " + endsWithWorld);
}
}

1
JAVA PRACTICAL 2106025

OUTPUT:-

2
JAVA PRACTICAL 2106025

Program 2:-Program for for implementing StringBuffer Functions:-

public class string_buffer{


public static void main(String[] args) { //2106025

StringBuffer stringBuffer = new StringBuffer("Hello, ");

stringBuffer.append("World!");
System.out.println("Appended Text: " + stringBuffer);

stringBuffer.insert(6, "Java ");


System.out.println("Inserted Text: " + stringBuffer);

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

stringBuffer.setCharAt(6, 'W');
System.out.println("Updated Text: " + stringBuffer);

int length = stringBuffer.length();


System.out.println("Length of StringBuffer: " + length);

stringBuffer.reverse();
System.out.println("Reversed Text: " + stringBuffer);

}
}

OUTPUT:-

You might also like