0

I need to write every single row of a textArea into an array after I click a button. However, I have no clue how to seperate the the rows of the input text so i can write them to an array. (or if this is possible at all with textareas?)

Example: Textarea: line1 line2 line3

After I lick a button, it will generate this array of Strings:

array[0]: line1
array[1]: line2
array[2]: line3

Thanks in advance.

1 Answer 1

4

You can do

String[] rows = textArea.getText().split("\n");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, does \n work for all operating systems? Sorry if thats a stupid question.
Yes: new lines are represented in a TextArea with \n on all platforms: assuming the user typed the text in. (If you load the text from a file, and the text file represents new lines in a different way, you may need to do some work to put the correct text into a text area, but that's a different situation.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.