Solved HashSet

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 26, 2016.

  1. Hello so I have this hashset

    Code (Java):
    Set<String> s = new HashSet<String>();
    s.addAll(ca.getConfig().getKeys(false));
    how do I convert them to ArrayList or List ?
     
  2. Code (Java):
    Set<String> s = new HashSet<String>();
    s.addAll(ca.getConfig().getKeys(false));
    String[] array = s.toArray(new String[s.size()]);
    List<String> list = Arrays.asList(array);
    This is how I'd do it.
     
  3. Code (Java):
    Set<String> s =new HashSet<String>();
    s.addAll(ca.getConfig().getKeys(false));
    ArrayList<String> list = new ArrayList<String>();
                        for(String names : s) {
                            list.add(names);
                        }

    this is what I did is it edible ?
     
  4. Why would you do it like that? That way just doesn't make sense.
     
    • Friendly Friendly x 1
  5. really ? got it works.
    you just made the Set strings to an array. nc try thanks for help at the same way.
     
  6. I converted it to the list pal, look at my code
     
  7. did I said something contradicts to that ? I think no that I'm aware of

    I said you just convert the set to string and convert to array

    then make another convertion of array to list.
     
    • Informative Informative x 1
  8. oh my bad I forgot that thingyy too.
     
  9. That works too but a lot of people don't understand how to use it, hash set extends array list I believe so it works all the same. I just didn't want to give out code that wasn't understandable to the op and others.
     
    • Informative Informative x 1
  10. well nc idea looking forward to you I hope you answer many more question in the way that they understand what you're solution is.
     
  11. Oops my bad :O it all boils down to collections huh, I've never looked too much into it ;) I might look more into it when I have the time but when it's 4:09 in the morning I don't really have the thinking power for it <3
     
  12. he didn't mean to be wrong but the way he wanted to answer people but this clearly contradicts what he said kinda cool and informative :D thanks for this.