This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Remove last element of string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Remove last element of string" Watch "Remove last element of string" New topic
Author

Remove last element of string

Sanj Sharma
Ranch Hand

Joined: Feb 14, 2004
Posts: 32
Hi

Any one who know how to remove the last element of string.
Say i have string "0000." and i just want to remove "." from it and make it "0000"
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
Originally posted by Girish Sharma:
Hi

Any one who know how to remove the last element of string.
Say i have string "0000." and i just want to remove "." from it and make it "0000"



Use substring() method of String class..Referring ur example



Thnx
Sanj Sharma
Ranch Hand

Joined: Feb 14, 2004
Posts: 32
Thanks, Nischal.
Sanj Sharma
Ranch Hand

Joined: Feb 14, 2004
Posts: 32
This will remove all the elements except last i want to remove last element only.
newgen pras
Ranch Hand

Joined: Jun 01, 2005
Posts: 34
This will remove the last element only ....

String str = "0000."
str = str.substring(0,str.length()-1)
System.out.println(str)


Regards
Prasanna
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
Be sure to test for the case of a zero-length string, otherwise you will get an exception.

Geoffrey


Sun Certified Programmer for the Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remove last element of string