I pull string from textarea by .gettext()
and it have a blankline.
test1111
test222
I need to split this String and keep into array, then array[0]=test1111
array[1]=test222
How can I do?
Something like this should work:
String[] lines = text.split("\\s*\\n+\\s*");
Or better if you're using Java 8 (per Pshemo), use "\\R+"
This will skip over multiple blank lines, or lines filled with white space, and should trim leading and ending whitespace as well.
String[] lines = jtextFieldName_you_used.getText().split("\\n");
It is to store textarea elements to array.Hope you find this helpful.
Try this.
String str = abc.getText();
for (String retval: str.split(" ")){ System.out.println(retval); }
If i understood your task right:
final String[] lines = data.split("\\n");
final String results[] = new String[lines.length];
int offset = 0;
for (String line : lines) {
results[offset] = line.split("\\s")[1];
offset++;
}
results:
test1111
blankline
test222
p.s: without data checks