Search code examples
javaswinguser-interfacejtextareasettext

How to output fields in an ArrayList to a JTextArea?


I'm trying to do something on the lines of:

    someJtextArea.setText(String.valueOf(
    for(int i = 1; i < 0; i++)
        {
            objInstance.anArrayList.get(i).getFirstName()
        }
    ));

Solution

  • Just append to the JTextArea:

    Your for loop constraints by the way are a little odd.

    For example:

    for (Person person: objInstance.anArrayList) {
       someJTextArea.append(person.getFirstName() + "\n");
    }
    

    (Sorry about my previous wrong answer as I initially thought that you were adding to a JTextField)