Results 1 to 4 of 4
  1. #1
    mahesh19nov is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Question Help regarding StringTokenizer

    Hey Guys:confused:,

    While running this code I am getting PatternSyntaxException..
    I don't know what is wrong in that...Please help me out!

    Java Code:
    public class TestPage
    {
        public static void main(String[] args)
        {
            TestHashMap objTestHashMap=new TestHashMap();
        }
    
    }
    
    class TestHashMap{
        public TestHashMap(){
            HashMap hMap=new HashMap();
            hMap.put("Name", "Test");
            hMap.put("Age", 26);
            hMap.put("Designation", "Software Engineer");
            System.out.println(hMap);
            String hMapString = hMap.toString();
            hMapString = hMapString.replaceAll("{", "");
            StringTokenizer hMapStringTokens=new StringTokenizer(hMapString, ",");
            while(hMapStringTokens.hasMoreTokens()){
                StringTokenizer keyValueTokens=new StringTokenizer(hMapStringTokens.nextToken(),"=");
                while(keyValueTokens.hasMoreTokens()){
                    System.out.println("Token->"+keyValueTokens.nextToken());
                }
            }
        }
    }
    Last edited by mahesh19nov; 10-26-2010 at 09:40 AM.

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Geek And Poke: The Geek Joke Of The Week
    D

    .replaceAll("{", "");

    --->

    .replaceAll("\\{", "");

    btw: why are you sing regex? .replace("{", ""); .....
    Last edited by eRaaaa; 10-26-2010 at 06:51 AM.

  3. #3
    mahesh19nov is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    Haven't you seen the output?I want to remove '}' from hMapString...First one is removed when I tried replace() but last one is still same...

  4. #4
    mahesh19nov is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    And yeah .replaceAll("\\{",""); is working...I am new and just trying to grasp concepts...

Similar Threads

  1. StringBuffer .. and stringtokenizer
    By javanew in forum New To Java
    Replies: 6
    Last Post: 05-20-2010, 01:21 AM
  2. Help with StringTokenizer!
    By ookie833 in forum New To Java
    Replies: 13
    Last Post: 12-14-2008, 04:09 PM
  3. StringTokenizer
    By carderne in forum New To Java
    Replies: 1
    Last Post: 01-26-2008, 08:19 PM
  4. StringTokenizer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-08-2007, 08:48 AM
  5. StringTokenizer
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-03-2007, 09:24 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
  •