File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Getting a required value from a String