-5

Suppose I've retrieved a text from EditText and stored it in a string:

String str = "Hello, I am new to Android.

Now i want to store the text in an array this way:

array={"Hello,","I","am","new","to","Android."};
Curly_Braces
  • 440
  • 2
  • 8
  • 15

4 Answers4

3

Split the string based on space and store it in an array. Take a look

str = "Hello, I am new to Android";
String[] splited = str.split("\\s+");
JBJ
  • 288
  • 2
  • 13
0

You split the string on the space character.

String[] array = str.split(" ");
MichaelStoddart
  • 5,571
  • 4
  • 27
  • 49
0

use below line of code
String []array = str.split(" ");

Sandeep dhiman
  • 1,863
  • 2
  • 17
  • 22
0
String string = "Hello, I am new to Android";
String[] parts = string.split(",");
String part1 = parts[0]; // Hello
String part2 = parts[1]; // I am new to Android

String[] partss = part2.split(" ");
String part11 = parts[0]; // I
String part22 = parts[1]; // am 
.....
Anmol317
  • 1,356
  • 1
  • 14
  • 31