Getting all strings in a HashSet

Discussion in 'Plugin Development' started by Jake230599, Nov 4, 2012.

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

    Jake230599

    I want to know how to turn this:
    Code:
    public HashSet<String> set = new HashSet<String>();
    Into a string which can be sent to players. So it would list everyone in the HashSet. Also how do I save that list of players to file?
     
  2. Offline

    Ranzdo

    You can iterate over most Collections in java (HashSet being one of them)
    Code:java
    1.  
    2. StringBuilder sb = new StringBuilder();
    3. for(String playerName : set) {
    4. sb.append(playerName+" ");
    5. }
    6. String theCombinedSet = sb.toString();
    7.  
     
    ferrybig likes this.
  3. Offline

    Sagacious_Zed Bukkit Docs

    The for loop can go over anything that is Iterable or an Array.
     
  4. Offline

    Jake230599

    So this can be output to players and txt files correct?
     
  5. Offline

    desht

    PHP:
    String s Joiner.on(" ").join(set);
    // that is all
     
  6. There is no Joiner class inside bukkit or java
     
  7. Offline

    desht

    Oh yes there is!
     
  8. Offline

    fireblast709

  9. Offline

    desht

    Wrong Joiner. We don't need any Oracle Virtual Directory API here ;)

    ferrybig fireblast709 Joiner (along with plenty other Google commons classes - that's the Joiner I'm talking about) is most certainly shipped with Bukkit, and has been for a long time.

    Code:
    $ unzip -l craftbukkit.jar  | grep Joiner
        1345  2012-11-03 05:06  com/google/common/base/Joiner$1.class
        2581  2012-11-03 05:06  com/google/common/base/Joiner$2.class
        4458  2012-11-03 05:06  com/google/common/base/Joiner$MapJoiner.class
        1012  2012-11-03 05:06  com/google/common/base/Joiner$3.class
        6124  2012-11-03 05:06  com/google/common/base/Joiner.class    <= Look!
    
    http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Joiner.html
     
  10. Offline

    fireblast709

    desht lol might explain why it was not found :3
     
Thread Status:
Not open for further replies.

Share This Page