What does the substring method of the String class do?
- Checks if the string is empty.
- Converts the string to lowercase.
- Retrieves the string's length.
- Returns a new string with a portion of the original string.
The substring() method of the String class in Java returns a new string that is a subset of the original string. It takes two parameters, the starting index and the ending index, and extracts the characters within that range, creating a new string. The other options do not describe the functionality of the substring() method.
Loading...
Related Quiz
- What will be the initial capacity of a HashSet when no size is defined during its creation?
- What is the significance of declaring a variable as transient?
- Which of the following methods can be used to create a stream from a collection?
- In memory, the rows of a two-dimensional array in Java can be __________.
- Can a constructor be private in Java?