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

Posted on 2006-04-25
Last Modified: 2010-03-31
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

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?
Question by:ryno71
    LVL 86

    Expert Comment

    >>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

    Author Comment

    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.


    Author Comment

    The text area would look something like this..



    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?

    LVL 30

    Expert Comment

    >> 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.
    LVL 86

    Accepted Solution

    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
    LVL 92

    Assisted Solution

    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);

    Author Comment

    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...
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
    This video teaches viewers about errors in exception handling.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now