Return String from String[]?

Discussion in 'Plugin Development' started by jusjus112, Feb 1, 2015.

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

    jusjus112

    Hey guys,

    Is there an way to return a normal String (that you can use in p.haspermissions(//String))
    So i have this little String array:
    Code:
    public final String[] staffPermissions = {
            "network.rank.owner", "network.rank.crew", "network.rank.moderator", "network.rank.builder",
            "network.rank.support", "network.rank.sponsor"
        };
    And i want to return it in a String, like this:
    Code:
    public String getStaffPermissions() {
            return staffPermissions;
        }
    But im getting a error, and i cant make it from a Strig[] to a normal string!
    Is there an way to do this?
     
  2. Offline

    nverdier

  3. Offline

    JasonT148796

    This will turn it all into one string that you can return,
    I wasn't sure if you wanted all of them on one line or not.
    If you want them all on one line remove the ' + "\n" ' part.

    Code:
        public final String getStaffPermissions(){
            String result;
            for(String perm : staffPermission){
                result = result + perm + " " + "\n";
            }
            return result;
               
        }
    Hope this helped, if something doesn't work tell me.
     
  4. Offline

    macboinc

    Code:
    StringBuilder builder = new StringBuilder();
    for (String s : staffPermisions) {
           builder.append(s);
    }
    
    String combinedStrings = builder.toString();
    
     
  5. Offline

    mine-care

  6. Offline

    1Rogue

    Or better yet:

    Code:java
    1. String yourNewString = StringUtils.join(yourArray, someDelimiterString);
     
Thread Status:
Not open for further replies.

Share This Page