I have an array with each element containing first and second names,
eg array[0] = bob dylan
array[1] = johny cash
I want to take those names, split them, and assign the first name to element[0] of a new array, and the surname to element[1] of the new array,
eg newArray[0] = bob
newArray[1] = dylon
newArray[2] = johny
newArray[3] = cash
Here's where I'm at so far:
String name;
for( int i = 0; i < array.length; i++ ){
System.out.println( "Enter the singers First name and Surname:" );
name = s.nextLine();
array[ i ] = name;
}
I've got both arrays ready but i'm unsure whether I need to take the array elements and assign them to a string 1 by 1, then split them and put them in a new array, or perhaps theres a way to look at each element of a string[] and split them and assign to a new array without needing to use seperate strings. Many Thanks
String
class, in particular thesplit
method, and also the Javadoc for theList
interface. – David Wallace 7 mins agobob dylan
andjohny cash
or is it only temporary array to create one withbob
dylan
johny
cash
elements? – Pshemo 5 mins ago