Question: Example: peter pan (or) jasmine cornflower

I want to read that in java, but want to split up the name and surname, 
for example, when user enter name and surname it must split it up and write name to name field and surname (second word) to surname field in database table USERS.

Is that possible?
If so how do I go about doing it?

Answer: 
Use [String](http://docs.oracle.com/javase/6/docs/api/java/lang/String.html) class and its split method.

```
String fullName = "peter pan";
String[] nameParts = name.split(" ");

System.out.println(nameParts[0] +" "+ nameParts[1]); // outputs peter pan

```
Well, you can always use [`String.split`](http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split%28java.lang.String%29):

```
    String input = "peter  pan";
    String[] split = input.split("\\s+");
    System.out.println("First name: " + split[0] + ", last name: " + split[1]);

```

the output:

```
    First name: peter, last name: pan

```

If you want to read from the command line, you can do this:

```
public static void main(String[] args) {
   if (args.length >= 2) {
     System.out.println("First name: " + args[0] + ", last name: " + args[1]);
   }
   else {
     System.out.println("Not enough arguments provided.\nInput line as array: "
         + Arrays.toString(args));
   }
 }

```