The correct answer is: B. Remove
The remove()
method is used to remove the specified number of characters located anywhere in the String.
The trim()
method is used to remove the leading and trailing whitespace characters from the String.
The truncate()
method is used to shorten the String to the specified length.
The deleteSpace()
method is used to remove all whitespace characters from the String.
Here is an example of how to use the remove()
method:
String str = "Hello World";
str.remove(3); // Removes the character at index 3, which is 'l'.
System.out.println(str); // Output: Helo World
Here is an example of how to use the trim()
method:
String str = " Hello World ";
str.trim(); // Removes all leading and trailing whitespace characters.
System.out.println(str); // Output: Hello World
Here is an example of how to use the truncate()
method:
String str = "Hello World";
str.truncate(5); // Shortens the String to 5 characters.
System.out.println(str); // Output: Helo
Here is an example of how to use the deleteSpace()
method:
String str = " Hello World ";
str.deleteSpace(); // Removes all whitespace characters.
System.out.println(str); // Output:HelloWorld