1).
Java Program for string Handling Functions
import java.util.Scanner;
public class StringHandlingProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get input from the user
System.out.print("Enter a string: ");
String input = scanner.nextLine();
// Display the length of the string
System.out.println("Length of the string: " + input.length());
// Convert the string to uppercase
String uppercase = input.toUpperCase();
System.out.println("Uppercase string: " + uppercase);
// Convert the string to lowercase
String lowercase = input.toLowerCase();
System.out.println("Lowercase string: " + lowercase);
// Check if the string contains a specific substring
System.out.print("Enter a substring to search for: ");
String substring = scanner.nextLine();
if (input.contains(substring)) {
System.out.println("String contains the substring.");
} else {
System.out.println("String does not contain the substring.");
}
// Get the index of a specific character in the string
System.out.print("Enter a character to search for: ");
char ch = scanner.nextLine().charAt(0);
int index = input.indexOf(ch);
if (index != -1) {
System.out.println("Character found at index " + index);
} else {
System.out.println("Character not found in the string.");
}
scanner.close();
}
}