Results 1 to 4 of 4
  1. #1
    reachjava is offline Member
    Join Date
    Jun 2011
    Posts
    10
    Rep Power
    0

    Default java implemengtation for duplicate key(s) and unique value(s).

    Hi,
    I am trying to look for an implementation, where in I have to implement a logic on a String variable. The String I will get is:

    String strVal ="New-value1:old-value1:New-value1:old-value1:New-value1:old-value1:New-value2:old-value2:New1-value1:old1-value1:New1-value2:New2-value2:old2-value2"

    I have to retrieve the values as key value pairs like each to be stored into a variable:

    String s1 ="New" ; String v1 ="value1"; (no repetition of value "value1" for key New or old,but key New/old to be repeated)
    String s2= "New" ;String v2="value2";
    String s3= "New" ; String v3="value3";
    String s4 ="New1" ;String v4="value1"; // may be I need to use arayList or hashmap or some other,
    String s5="New1" ;String v5=" value2"; but I am not sure what is best to use for this requirement.
    String s6="old" ;String v6="value1";
    String s7="old";String v7="value2";
    String s8="old1";String v8="value1";
    String s9="old1";String v9="value2";
    String s10="New2"; String v10="value2";
    String s11="old2" ; String v11="value2";

    and so on..


    Please help how to code this in java.

    Thanks.
    Last edited by reachjava; 07-01-2011 at 08:32 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Start with the parsing part. Break the String up into the key/value pairs.
    I'm not sure what you want to do next.
    Given the input you have shown, what data do you want saved and where do you want it?
    Can you use some of Java's classes like a HashMap?

  3. #3
    reachjava is offline Member
    Join Date
    Jun 2011
    Posts
    10
    Rep Power
    0

    Default

    Hi Norm,
    thanks for your reply. I want to store these values into database table, like :

    column1 column2
    New value1
    New value2
    New value3
    Old value1
    Old value2
    Old value3
    New1 value1
    Old1 value1


    like that I have to add into a databse table which does n't have any restrictions on the table columns.


    Pls advice how to do this in java.

    Start with the parsing part. Break the String up into the key/value pairs. (can you pls tell me how to do this in java).

    Thanks.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Break the String up into the key/value pairs.
    Look at the String class and the StringTokenizer class.

    Since the keys(column1) have multiple values(column2), you'll need to have a collection (like an ArrayList) to hold the values for each key.

    I don't program databases so I have no idea what you mean by a database table.

Similar Threads

  1. How to make element unique in Java Collection
    By jeanjiang in forum New To Java
    Replies: 2
    Last Post: 04-25-2011, 11:53 AM
  2. Check for unique key violation
    By andy16 in forum JDBC
    Replies: 6
    Last Post: 05-24-2010, 06:23 PM
  3. Replies: 0
    Last Post: 03-04-2010, 10:44 AM
  4. Generate unique letters
    By bl00dr3d in forum New To Java
    Replies: 22
    Last Post: 04-10-2009, 02:44 PM
  5. Unique element in an array
    By revathi17 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 08:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •