how to convert a set into a string

Discussion in 'Plugin Development' started by 991jo, Jan 26, 2012.

Thread Status:
Not open for further replies.
  1. Offline



    from a getKeys(false) I get a set, which contains the Keys of a Yaml-file. how can i get a String, which contains all the keys of the set? I need something like:

    Key1, Key2, Key3, Key4, ...

    I hope you can help me.
  2. Code:
                StringBuilder sb = new StringBuilder();
                for(java.util.Map.Entry<String,Object> entry : mySet.entryset())
                    //add a "," before every entry, except for the first one
                    if(sb.toString().length() > 0)
                        sb.append(", ");
                    //append the string
                //work with string
                String myConatinatedString = sb.toString();
    You may have to adjust the Entry's typeparameter for your needs.
  3. Offline


    Thank you, I hope this works. Could you please explain this a bit further? I don't want wo use code, that I don't understand.
  4. Offline


    just use
    Set<String> keys = config.getKeys(false);
    String newString = keys.toString().subString(1, keys.size()-1 );
Thread Status:
Not open for further replies.

Share This Page