Complete the code to get the length of the string.
String text = "Hello"; int length = text.[1]();
The length() method returns the number of characters in a string.
Complete the code to convert the string to uppercase letters.
String word = "java"; String upper = word.[1]();
The toUpperCase() method converts all letters in the string to uppercase.
Fix the error in the code to check if the string starts with "Hi".
String greeting = "Hi there!"; boolean starts = greeting.[1]("Hi");
The correct method to check the start of a string is startsWith().
Fill both blanks to extract the substring "cat" from the word "concatenate".
String word = "concatenate"; String part = word.[1](3, [2]);
The substring(int start, int end) method extracts characters from start index up to but not including end index. Here, indexes 3 to 6 give "cat".
Fill all three blanks to create a new string with trimmed spaces and replaced spaces with underscores.
String messy = " hello world "; String clean = messy.[1]().[2](" ", [3]);
trim() removes spaces at the start and end. replace(" ", "_") changes spaces inside the string to underscores.
