Best way to find data in a variable length ASCII text area where the property data (key/values pairs) may be always different

What would the best way to find items in a variable length ASCII text area where the data (is set up like a property file with key/values pairs but may be always different).  I will know the different types of key/value pairs but they might change (new ones added or old ones removed)

say text area could have
First Name=Chris
Last Name=Willis

Next text area I am sent could have
Street Name=100 Main Street
City Name=New York

Next one could have
userid=2010
password=password


I know I probably should treat it as a property file.. using Properties class and use the get method, but where would be the best way/place to put the items you are looking for in an Araylist?

Or would you just move the text area over to a hashmap and try to get the key/value pairs from there?
The message area will only have one of the 3 at a time though, so don't know the best way without searching the text area with all of them...

any suggestions?
ryno71
ryno71Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>but where would be the best way/place to put the items you are looking for in an Araylist?

How do you mean? They'd already be in a Map if you're using Properties
0
ryno71Author Commented:
Let me rephrase I am given an object that contains a variable length ascii text area...  should I place this into a hashmap so I could use the Properties class (best way) AND what would be the best way to search for the 3 types... as when I have firstname I would know last names would be next or if I had username I would know password would be next, etc.


0
ryno71Author Commented:
The text area would look something like this..


FirstName=Chris
LastName=Willis
FirstName=John
LastName=Taylor
FirstName=John
LastName=Gleese

or

Street Name=100 Main Street
City Name=New York
Street Name=200 Main Street
City Name=Denver
Street Name=500 Main Street
City Name=York

Should i place the items I want to search for in an ArrayList  as (FirstName,LastName)  (Street Name, City NAme) and place the values after I find them back in that type of format in an arraylist?
John,Gleese
John,Taylor

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Mayank SAssociate Director - Product EngineeringCommented:
>> should I place this into a hashmap so I could use the Properties class (best way)

Properties is related to HashMap in a way, that both are maps. Properties is synchronized (thread-safe) so don't bother about using a HashMap.

>> when I have firstname I would know last names would be next

In all maps, the order becomes irrelevant. So just search based on the key.
0
CEHJCommented:
You would probably be best to keep two views of the data
a. a single String that you can use to do pattern matching
b. a Properties view so you can retrieve key/value pairs
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
objectsCommented:
try the following to load your map:

Properties map = new Properties();
map.load(new ByteArrayInputStream(textArea.getText().getBytes()));

you can then get the set of keys using:

Set keys = props.keySet();

And get a value using:

String value = map.getProperty(key);
0
ryno71Author Commented:
Luckily for me I am being passed a Property list... so I wont need to do anything fancy..

Could just do an enumeration then with a typical while ( enum.hasMoreElement()) and put the values into an Arraylist.  I will just grab the keys from a configuration file.  I always forget the K.I.S.S rule!

Thanks for the help guys...
ryno71
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.