This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Java in General and the fly likes Getting a required value from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting a required value from a String" Watch "Getting a required value from a String" New topic

Getting a required value from a String

sivaprasad pasupulathi
Ranch Hand

Joined: Apr 21, 2009
Posts: 36

This may sound strange but I would like to know if there is a better solution for my question.

I have a String say

String abc = " India = Delhi,USA=Washington,UK=London";

I would like to get the values by specifying the country Name.If I want to get the value for India,I should get the corresponding value.I Don't want to use StringTokenizer.I want to know if there are any function in Java6 which can improve my code reading.

John de Michele

Joined: Mar 09, 2009
Posts: 600

You'll be much better off splitting that String up into a Map. Maps use key, value pairs, and allow very quick searching by keys.

I agree. Here's the link:
subject: Getting a required value from a String