Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

JAVA PRACTICAL 2106066

Program 1:-Program for implementing String functions :-

public class string_functions {


public static void main(String[] args) { //2106066
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 2106066

OUTPUT:-

2
JAVA PRACTICAL 2106066

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

public class string_buffer{


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

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