Since this is Java 8, you can use:
textArea.setText( textArea.getText()
+ String.join( System.lineSeparator(), linkedHashSet ));
The various forms of String.join
, this one accepting a delimiter and an Iterable
, let you join together the elements' string representations with a delimiter - in this case a line separator.
Usually, if your Iterable
(set, list) has elements "A", "B" and "C", and you want to join them with ,
, you use:
String.join( ",", myIterable );
And this will give you:
A,B,C
If the first parameter was ---BIG DELIMITER---
, then you would get:
A---BIG DELIMITER---B---BIG DELIMITER---C
But in our case, we put in the System.lineSeparator()
, which means that your strings will be separated by \n
(on Linux machines), or \r\n
(on Windows machines). This means that each of the values will be on a separate line:
A
B
C