Question:
How can you split a string into multiple string objects?
Answer:
Use the string method split().
Code:
public class SplitString { public static void main(String[] args) { String members = "Paul:John:George:Ringo"; String[] beatles = members.split(":"); System.out.println("beatles.size: " + beatles.length); for(String name: beatles){ System.out.println(name); } } }
Output:
$ java SplitString beatles.size: 4 Paul John George Ringo