java - How to store a splitted string into an array? -


the problem here that, don't know how insert array, given for-each loop. wanted that, for-each string splitted, splitted string gets stored in array, instead of printing out.

system.out.println("input string: ");  scanner s = new scanner(system.in); string input = s.nextline();  string[] longstr = input.split("(?<=\\.\\s)");                           system.out.println("output:\n");           for(string shortstr : longstr){              system.out.println(shortstr);               } 

input string:

imagine me , you, do. think day , night. it's right.

output

imagine me , you, do.

i think day , night.

it's right.

proposed code output

for(string shortstr : longstr){      //store shortstr in array      }      //call arrays of shortstr same output dictated above 

is possible?

arraylist<string>  result = new arraylist<>(); for(string shortstr : longstr){     //system.out.println(shortstr);      result.add(shortstr); }  int pos=5; string item=result.get(pos); //to item @ pos 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -