Hui Ting Ko Hui Ting Ko - 1 year ago 85
Java Question

How can I take out the element from a String?

For example, if I have a string "Hello how are you". After I use the

to separate all the elements, I want to put "Hello" to a variable, also same as the remainings, which method should I use to do it as it is not an ArrayList so I can't use the index.
Lots of thanks.

Answer Source

You can achieve the same like this :-

String input = "Hello how are you";
String[] splittedString = input.split(" ");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download