Java Data Type How to - Split String with delimiter and holding the values








Question

We would like to know how to split String with delimiter and holding the values.

Answer

import java.util.Scanner;
/*  w  ww. j  a v  a 2 s  .c o m*/
public class Main {
  public static void main(String[] args) {
    String str = "start 1 2 123455";
    Scanner sc = new Scanner(str);
    String param1 = sc.next();
    int param2 = sc.nextInt();
    int param3 = sc.nextInt();
    int param4 = sc.nextInt();
    System.out.println(param1 + "\t" + param2 + "\t" + param3 + "\t" + param4);
  }
}