Adding multiple messages to a list

Discussion in 'Spigot Plugin Development' started by Rlaxing, May 29, 2016.

  1. Hello, I have a command that saves the players message to the config. I am trying to convert it, so when adding a new message, it doesn't overwrite the last one, but simply adds it to the list. Whats the best way to do this?

    Code (Text):
                                ArrayList<String> list = new ArrayList<String>();

                                //iterating through the arguments turning them into a string
                                for (int i = 1; i < args.length; i++) {
                                    message += args[i] + " ";
  2. Replace message += to message = message + args + " ";
    I find that += doesn't work with Strings
  3. That part of it is working fine. I need to add the message to a list everytime.
  4. Use StringBuilders!
    Code (Java):

    StringBuilder builder = new StringBuilder();

    //now you can go through the arts
    for(String argument : args){
    // add it to the builder
      builder.append(argument + " ");
    //now you can do
    String allArgs = builder.toString();
  5. well I don't see this string at your code but I guess its in your class because you said such thing that this method is already working

    Code (Java):
    String message = "";
    try doing this when you're adding the message in the list

    Code (Java):

    no it would work with strings.