Beginner Java - using substring() to make a long string into seperate lines
<p>We are suppose to write a calendar for a project.  I'm using an array to keep track of how many days in a month there are and get a long list of numbers equal to the value of that array index.  I then populate a String using a loop until that loop is equal to the value of that index.</p>

<p>The string is loaded into a textshape, which was given by our professor.  I want to display each text line that is generated by substring() into one separate line.  I tried to start at a higher index (30, 59) but it returns an error b/c my initial string isn't long enough.</p>

<p>So what i want to do is make that long list of numbers into separate lines.  A classmate of mine said to use substring. It does work, generally but will only give me the first line.  </p>

<p>this is the method to generate my string.  </p>

<pre><code>    public String toString() {

    monthPlusOne = month + 1;
    for (int i = 0; i &lt; monthsArray[monthPlusOne]; i++) {
        String temp;
        //temp = "" + i;
        subLine = subLine + (i+1) + " ";

        }
    totalLine = subLine;


    String output = monthText + " " + year + " \n "
            + "Su Mo Tu We Th Fr Sa\n" + totalLine;

    return output;
}
</code></pre>

<p>it feeds into this this method which origanlly had the calender in just number form with manual "\n" inserted into it.  The string would split when it found those "\n"</p>

<pre><code>public static void displayCalendar() {
    String s = calendar.toString().substring(30);

    // extract all of the lines in s
    // split s on \n
    String[] lines = s.split("\n");
    int index = 0;
    for (String line : lines) {
        t[index].setText(line);
        index++;
    }
}
</code></pre>
