Lines of JTextArea to an ArrayList<String>
java, jtextarea, newline, string, swing
Solution
embrace the power of `Strig.split(regex)` and `Arrays.asList` function:
String s[] = jTextArea1.getText().split("\\r?\\n");
ArrayList<String>arrList = new ArrayList<>(Arrays.asList(s)) ;
System.out.println(arrList);
Problem
How would one convert every line in a `JTextArea` into an `ArrayList<String>`? That is, how does one detect line breaks in a JTextArea? Here is my current pseudo code implementation: - get text from JTextArea - Go through every char in JTextArea and adds it to a string called currentWord until it finds a line break char //(does such a thing exist?) - When the loop detects a line break, it adds currentWord to the arrayList and sets currentWord to empty. - After the loop ends, add currrentWord to the ArrayList. 1. Is there an easier way to do this? 2. Does this implementation scale well with size? (I'm guessing no)