M. Rogers
M. Rogers

Reputation: 399

How to store a single line from JTextArea to String

I have a JTextArea. Suppose a user adds 5 lines of text into it. I want to add store each line as its own string in an Array of strings once my buttonClicked method is called. Any ideas of how to go about this?

Upvotes: 0

Views: 156

Answers (1)

Dylan Wheeler
Dylan Wheeler

Reputation: 7074

This code will take the text inside of your JTextArea called area, split it by each new line, and then store each of those lines into an array called array.

final String[] array = area.getText().split("\n");

Upvotes: 1

Related Questions