This content has been marked as final. Show 4 replies
Just make a substring of the string that excludes the last character.
String smallerString = apple.substring(0,apple.length() - 2)
If you ever have any questions on functionality of an Object, you should always check the API documentation.
Thanks for the correction!No problem.
It occurs to me that the OP might be wanting to shorten a given string "inplace" as it were. That can't be done. A String, unlike a StringBuilder/Buffer, doesn't change its contents once it's created. So you would have to assign a new String
apple = apple.substring(0,apple.length() - 1);