Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. /* String to split. */
  2. String str = "Robert King";
  3.  
  4. String[] temp;
  5.  
  6. String delimiter = " ";
  7.  
  8.  
  9.  
  10. temp = str.split(delimiter);
  11. String name = temp[0];
  12. String surname = temp[1];
  13.  
  14. String fullname = "Robert King";
  15. String[] names = fullname.split(" ", 1); // "1" means stop splitting after one space
  16. String firstName = names[0];
  17. String lastName = names[1];
  18.  
  19. String firstName = fullName.split(" ")[0];
  20. String lastName = fullName.split(" ")[1];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement