new Scanner(String instr) : Scanner « java.util « Java by API






new Scanner(String instr)

 
/**
 *Output:
28
 */

import java.util.Scanner;

public class MainClass {
  public static void main(String args[]) {
    String instr = "Name: Joe Age: 28 ID: 77";

    Scanner conin = new Scanner(instr);

    conin.findInLine("Age:"); // find Age

    if (conin.hasNext())
      System.out.println(conin.next());
    else
      System.out.println("Error!");

  }
}

           
         
  








Related examples in the same category

1.new Scanner(FileReader file)
2.new Scanner(InputStream source)
3.new Scanner(Readable source)
4.Scanner: findInLine(String str)
5.Scanner: findWithinHorizon(String pattern, int horizon)
6.Scanner: hasNext()
7.Scanner: hasNextBoolean()
8.Scanner: hasNextDouble()
9.Scanner: hasNextInt()
10.Scanner: hasNextLine()
11.Scanner: next()
12.Scanner: nextBoolean()
13.Scanner: nextDouble()
14.Scanner: nextInt()
15.Scanner: nextLine()
16.Scanner: useDelimiter(String pattern)