Get an array of entered split values

I have TextAreawith input of split values:

Example:

Value1

Value2

Value3

Value4

Value5

Is there a quick way to put them in an array String

String[] newStringArray = ???
+3
source share
2 answers

Do you want to use String.split(String regex):

Returns: an array of strings calculated by breaking this string around matches of a given regular expression

So maybe something like this:

String[] newStringArray = textAreaContent.split("\n");

This splits the string textAreaContentaround matches "\n", which is the normalized line break for Swing text editors (as specified in the javax.swing.text.DefaultEditorKitAPI ):

[...], , "\n" , , , . "\n".

(, ?), , .


    String[] parts = "xx;yyy;z".split(";");
    for (String part : parts) {
        System.out.println("<" + part + ">");   
    }

:

<xx>
<yyy>
<z>

:

    String[] lines = "\n\nLine1\n\n\nLine2\nLine3".trim().split("\n+");
    for (String line : lines) {
        System.out.println("<" + line + ">");           
    }

:

<Line1>
<Line2>
<Line3>
+3

String.split(). TextArea TextArea, :

String[] values = textArea.getText().split("\n");
+6

Source: https://habr.com/ru/post/1748123/


All Articles