I want to manipulate this string:
"Roger:Rabbit:22:California"
and display the output as follows:
Name: Roger Rabbit
Age: 22
State: California
I am wondering what will be the best approached to this?
I want to manipulate this string:
"Roger:Rabbit:22:California"
and display the output as follows:
Name: Roger Rabbit
Age: 22
State: California
I am wondering what will be the best approached to this?
For this you may use the String split()
method. Mention your delimiter as :
. Then you want to make sure you create an array out of the output of your split method with the different strings split. In your System.out.println()
you can mention the array index of your newly created array elements as System.out.println("Name" + myIndex[0])
.
Resource: https://www.tutorialspoint.com/java/java_string_split.htm