I have a HashMap. The key will be a string and value can be anything ranging from a variable to a ArrayList.
The problem is I have an ArrayList. The values stored in the ArrayList are Region1,Region2,Region3,Region4.
So when I put this ArrayList in HashMap and print the HashMap I get the output as
[Region1,Region2,Region3,Region4].
Problem is I need to insert this whole comma separated String in Db and my procedure cannot recognize [] in this output.
How can I solve it..I cannot change anything at DB end.
Here’s the code snippet:-
ArrayList<String> Region=new ArrayList<String>();
Region.add("Region1");
Region.add("Region2");
Region.add("Region3");
System.out.println(Region);
Output is [Region1, Region2, Region3]
I put this ArrayList in HashMap
HashMap<String,Object> regionHashMap=new HashMap<String,Object>();
regionHashMap.put("regionssss", Region);
System.out.println(regionHashMap);
Output is {regionssss=[Region1, Region2, Region3]}.
How can i Remove [] from the ArrayList…
I already succedded by using StringBuffer and Iterator but I cannot use it everytime Since I have huge number of ArrayList which will go inside the HashMap..
The String representation of a List automatically encloses with “[ ]” characters.
You could either create your own ‘toString’ method:
Or, you could use the substring function to remove the braces: