Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6786605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:15:56+00:00 2026-05-26T17:15:56+00:00

I have a HashMap. The key will be a string and value can be

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:15:57+00:00Added an answer on May 26, 2026 at 5:15 pm

    The String representation of a List automatically encloses with “[ ]” characters.
    You could either create your own ‘toString’ method:

    private String listToString(List<?> l) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < l.size(); i++) {
            sb.append(l.get(i));
            if (i != l.size() -1) sb.append(", ");
        }
        return sb.toString();
    }
    

    Or, you could use the substring function to remove the braces:

    String s = list.toString();
    s = s.substring(1, s.length()-1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a hashmap where every key has many values(stored in a arraylist). How
I have HashMap object contains a key x-y-z with corresponding value test-test1-test2 . Map<String,String>
I have a HashMap where the key is a word and the value is
I have a hashmap with some information(key and value) in a perl file. I
I have the following code private Map<KEY, Object> values = new HashMap<KEY, Object>(); public
I am going to have a string like hello world as a hashmap key.
I am getting this strange output in HashMap . I have two ArrayList<String> one
In my spring application context file, I have something like: <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String"
I have the following problem: I would like to change value of ExpandableListView's cell
I have a Map of Lists with key = GROUP and value = List

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.