Home | Computer Science

String


Definition

String functions in Java allow for manipulation of string data, while escape characters are used to include special characters in strings.


String Functions in Java

Common string functions:

Escape Characters in Java

Common escape characters:

Program

Input:

// Java program demonstrating string functions and escape characters public class StringFunctionsExample { public static void main(String[] args) { String str = "Hello World"; // String Functions System.out.println("Original string: " + str); System.out.println("Lowercase: " + str.toLowerCase()); System.out.println("Uppercase: " + str.toUpperCase()); System.out.println("Length: " + str.length()); System.out.println("Position of 'World': " + str.indexOf("World")); String str2 = " Goodbye"; System.out.println("Concatenated string: " + str.concat(str2)); // Escape Characters System.out.println("He said, \"Hello!\""); System.out.println("I\'m here"); System.out.println("This is a new line\nAnd this is another line"); } }

OUTPUT