Mega Code Archive

 
Categories / Java Tutorial / File
 

Searching for the specified pattern within the next line of text

String findInLine(Pattern pattern) String findInLine(String pattern) If the pattern is found, the matching token is consumed and returned. Otherwise, null is returned. import java.util.Scanner; public class MainClass {   public static void main(String args[]) {     Scanner sc = new Scanner("Name: Tom Age: 28 ID: 77");     sc.findInLine("ID:");     if (sc.hasNext())       System.out.println(sc.next());     else       System.out.println("Error!");   } } 77