Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 05:18 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
Reversing String
Hi

I have following String:

Code:
String s = "j1.2, s2.2, l3.2, p2.2, kl5.5";
I want to reverse it. I can do this character by character but its hectic of course

Is there a better way? Thanks in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-30-2007, 05:36 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
I would probably change the String to a character array and then just step through it backwards. That's probably what you are already doing. So to answer your question, not that I know of.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 10:40 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
Thanks.
So there is no reverseString() method available. SAD
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-01-2007, 10:56 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Code:
public static String reverseString(String s) { char[] strArr = s.toCharArray(); String output = ""; // read string backwards for (int i = strArr.length-1; i >= 0; i --) { output += strArr[i]; } return output; }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-02-2007, 10:42 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
Its works fine. Thanks for the help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using java.util.Scanner to search for a String in a String Java Tip Java Tips 0 11-20-2007 05:59 PM
reversing Strings Java Tip Java Tips 0 11-11-2007 09:24 PM
reversing a string toad New To Java 5 11-07-2007 10:13 AM
Help with insertName(String name) and deleteName(String name) trill New To Java 1 08-07-2007 08:29 AM
I can't seem to pass the value of a string variable into a string array mathias Java Applets 1 08-03-2007 11:52 AM


All times are GMT +3. The time now is 02:26 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org