Results 1 to 2 of 2
  1. #1
    busdude is offline Member
    Join Date
    Oct 2008
    Posts
    25
    Rep Power
    0

    Default How to update a String value in a map?

    I have a treeMap that maps a string to a string

    TreeMap<String, String> dictionary = new TreeMap<String, String>();


    I also have an arrayList of strings that need to be iterated through and every term has to be placed inside the treemap mapping to a string "p" if it doesn't exist in there already, and if it does I need to replace the previous value by concatenating another "p" to the old one,
    so if a particular string appears in the arraylist 3 times, its will map to the value "ppp".


    I know for integer values you can use a intValue() but I can't find something I can use similar to that.




    Java Code:
    if (dictionary.containsKey(terms.get(j)){
    	String val = ((String) dictionary.get(terms.get(j)[k])). -I don't know what to put here -  ();
    	dictionary.put(terms.get(j)[k], new String(val.concat("p"));
    					
    				}
    else if(!dictionary.containsKey(terms.get(j)){
    		dictionary.put(terms.get(j)[k],"p");
    					
    				}


    Is there some method I can use to obtain the old string value and then change it?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: How to update a String value in a map?

    I'm not sure what you are asking...the Map should return the string when you call get(), then you can concatenate the next string on it and call put to replace the previous.

Similar Threads

  1. Replies: 12
    Last Post: 11-26-2010, 08:33 AM
  2. Replies: 1
    Last Post: 11-04-2010, 06:53 PM
  3. How to update my jdk???
    By low224 in forum New To Java
    Replies: 4
    Last Post: 01-04-2009, 04:51 PM
  4. can i update the tag value of XMl file by other value(string
    By pankaj_salwan in forum Advanced Java
    Replies: 7
    Last Post: 07-04-2008, 08:12 AM
  5. Using sql:update tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 11:49 PM

Posting Permissions

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