title: Strings from ArrayList to individual strings JAVA
body: <p>Is there a way to "extract" individual strings from an ArrayList?
  I have stored strings in an ArrayList and want to print them to the console.
  I know that I can use a for-loop but it isn't quite that simple. I'm trying to create a column based print and I use a method (Created by "CandiedOrange" here on stack overflow) that takes strings separated by commas as input.</p>
  
  <p>What it basically does is; It creates column spacing based on the length of strings in each column. (All credit to "CandiedOrange")</p>
  
  <pre><code>List&lt;List&lt;String&gt;&gt; lines = new ArrayList&lt;&gt;();
  List&lt;Integer&gt; maxLengths = new ArrayList&lt;&gt;();
  int numColumns = -1;
  
  public Columns addLine(String... line) {
  
      if (numColumns == -1){
          numColumns = line.length;
          for(int i = 0; i &lt; numColumns; i++) {
              maxLengths.add(0);
          }
      }
  
      if (numColumns != line.length) {
          throw new IllegalArgumentException();
      }
  
      for(int i = 0; i &lt; numColumns; i++) {
          maxLengths.set(  i, Math.max( maxLengths.get(i), line[i].length() )  );
      }
  
      lines.add( Arrays.asList(line) );
  
      return this;
  }
  </code></pre>
  
  <p>The number of columns I want to print is unknown during compile time because the user enters the number of columns 1-5 during run time. So I figured I could use ArrayLists for the rows and use the addLine() method with each of the arraylists for the rows.</p>
  
  <p>If there Is a better way of solving this, I'd be more than happy to know.</p>
  
  <p>EDIT:</p>
  
  <p>From the start:</p>
  
  <p>I'm creating a Yahtzee game with 1-5 players. Each Player is defined by instances of the class "Player"</p>
  
  <pre><code>public class Player {
  
  private String name;
  
  private int ones;
  private int twos;
  private int threes;
  private int fours;
  private int fives;
  private int sixes;
  
  private int threeofakind;
  private int fourofakind;
  private int fullhouse;
  private int smallstraight;
  private int largestraight;
  private int chance;
  private int yahtzee;
  
  private int totalscore;
  
  public int getOnes() {
      return ones;
  }
  
  public void setOnes(int ones) {
      this.ones = ones;
  }
  
  public int getTwos() {
      return twos;
  }
  
  public void setTwos(int twos) {
      this.twos = twos;
  }
  
  public int getThrees() {
      return threes;
  }
  
  public void setThrees(int threes) {
      this.threes = threes;
  }
  
  public int getFours() {
      return fours;
  }
  
  public void setFours(int fours) {
      this.fours = fours;
  }
  
  public int getFives() {
      return fives;
  }
  
  public void setFives(int fives) {
      this.fives = fives;
  }
  
  public int getSixes() {
      return sixes;
  }
  
  public void setSixes(int sixes) {
      this.sixes = sixes;
  }
  
  public int getThreeofakind() {
      return threeofakind;
  }
  
  public void setThreeofakind(int threeofakind) {
      this.threeofakind = threeofakind;
  }
  
  public int getFourofakind() {
      return fourofakind;
  }
  
  public void setFourofakind(int fourofakind) {
      this.fourofakind = fourofakind;
  }
  
  public int getFullhouse() {
      return fullhouse;
  }
  
  public void setFullhouse(int fullhouse) {
      this.fullhouse = fullhouse;
  }
  
  public int getSmallstraight() {
      return smallstraight;
  }
  
  public void setSmallstraight(int smallstraight) {
      this.smallstraight = smallstraight;
  }
  
  public int getLargestraight() {
      return largestraight;
  }
  
  public void setLargestraight(int largestraight) {
      this.largestraight = largestraight;
  }
  
  public int getChance() {
      return chance;
  }
  
  public void setChance(int chance) {
      this.chance = chance;
  }
  
  public int getYahtzee() {
      return yahtzee;
  }
  
  public void setYahtzee(int yahtzee) {
      this.yahtzee = yahtzee;
  }
  
  public int getTotalscore() {
      return totalscore;
  }
  
  public void setTotalscore(int totalscore) {
      this.totalscore = totalscore;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm implementing MVC structure (to the best of my ability) which means that I have a View class with a method to display the main console column scoreboard. (Method unfinished)</p>
  
  <pre><code>public void displayMainScoreBoard(ArrayList&lt;Player&gt; playerList) {
  
      Columns col = new Columns();                                //Instance of column class.
  
      ArrayList&lt;String&gt; Name = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Ones = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Twos = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Threes = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Fours = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Fives = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Sixes = new ArrayList&lt;&gt;();
  
      ArrayList&lt;Integer&gt; Threeofakind = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Fourofakind = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Fullhouse = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Smallstraight = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Largestraight = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Chance = new ArrayList&lt;&gt;();
      ArrayList&lt;Integer&gt; Yahtzee = new ArrayList&lt;&gt;();
  
      ArrayList&lt;Integer&gt; Totalscore = new ArrayList&lt;&gt;();
  
      for (Player p : playerList) {                           //For every player, append their category data.
          Name.add(p.getName());
          Ones.add(p.getOnes());
          Twos.add(p.getTwos());
          Threes.add(p.getThrees());
          Fours.add(p.getFours());
          Fives.add(p.getFives());
          Sixes.add(p.getSixes());
  
          Threeofakind.add(p.getThreeofakind());
          Fourofakind.add(p.getFourofakind());
          Fullhouse.add(p.getFullhouse());
          Smallstraight.add(p.getSmallstraight());
          Largestraight.add(p.getLargestraight());
          Chance.add(p.getChance());
          Yahtzee.add(p.getYahtzee());
          Totalscore.add(p.getTotalscore());
      }
  
  }
  </code></pre>
  
  <p>And heres CandiedOrange's full Column class. (Again, I claim no rights to his code.)</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  
  public class Columns {
  
  List&lt;List&lt;String&gt;&gt; lines = new ArrayList&lt;&gt;();
  List&lt;Integer&gt; maxLengths = new ArrayList&lt;&gt;();
  int numColumns = -1;
  
  public Columns addLine(String... line) {
  
      if (numColumns == -1){
          numColumns = line.length;
          for(int i = 0; i &lt; numColumns; i++) {
              maxLengths.add(0);
          }
      }
  
      if (numColumns != line.length) {
          throw new IllegalArgumentException();
      }
  
      for(int i = 0; i &lt; numColumns; i++) {
          maxLengths.set(  i, Math.max( maxLengths.get(i), line[i].length() )  );
      }
  
      lines.add( Arrays.asList(line) );
  
      return this;
  }
  
  public void print(){
      System.out.println( toString() );
  }
  
  public String toString(){
      String result = "";
      for(List&lt;String&gt; line : lines) {
          for(int i = 0; i &lt; numColumns; i++) {
              result += pad( line.get(i), maxLengths.get(i) + 1 );
          }
          result += System.lineSeparator();
      }
      return result;
  }
  
  private String pad(String word, int newLength){
      while (word.length() &lt; newLength) {
          word += " ";
      }
      return word;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>How can I pass the Strings of my ArrayLists in my view to the addLine() Method?</p>