I have full name (ex : Robert King) separated by space in Database. I want to split the full name to FIRSTNAME and LASTNAME and assign it to two variables. How to achieve this in JAVA? I know it is simple but found it difficult to assign to two variable after split.
You can only assign to a single variable in java, so you'll need two steps:
String fullname = "Robert King";
String[] names = fullname.split(" ", 1); // "1" means stop splitting after one space
String firstName = names[0];
String lastName = names[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With