A 4
A 4
Here are some commonly used methods of the String class in Java, along with
examples:
3. `substring(startIndex, endIndex)`: Returns a new string that is a substring of the original string,
starting from startIndex (inclusive) and ending at endIndex (exclusive).
These are just a few examples of the many methods available in the String class. Each method
serves a specific purpose and allows you to manipulate and work with strings effectively in
Java
left++;
right--;
}
return true;
}
if (isPalindrome(input)) {
System.out.println("The string is a palindrome.");
} else {
System.out.println("The string is not a palindrome.");
}
}
}
In this program, the `isPalindrome` method takes a string as input and checks if it is a
palindrome. It removes any whitespace and converts the string to lowercase to ignore case
sensitivity. Then, it uses two pointers (`left` and `right`) to compare characters from the
beginning and end of the string, moving towards the center. If any pair of characters doesn't
match, the method returns `false`. If all characters match, it returns `true`.
In the `main` method, an example input string "level" is used to demonstrate the usage of the
`isPalindrome` method. The program prints either "The string is a palindrome." or "The string is
not a palindrome." based on the result of the palindrome check.