find in line java

Solutions on MaxInterview for find in line java by the best coders in the world

showing results for - "find in line java"
Lennard
23 Mar 2020
1// Java program to illustrate the 
2// findInLine() method of Scanner class in Java 
3
4import java.util.*; 
5import java.util.regex.Pattern; 
6
7public class GFG1 { 
8	public static void main(String[] argv) 
9		throws Exception 
10	{ 
11
12		try { 
13
14			// Get the string to be searched 
15			String s = "Geeksforgeeks has Scanner Class Methods"; 
16
17			// Print the string 
18			System.out.println("Target String:\n" + s); 
19
20			// create a new scanner 
21			// with the specified String Object 
22			Scanner scanner = new Scanner(s); 
23
24			// finds a pattern of any 5 letter plus "for" 
25			System.out.println("\nAny 5 letter plus for : "
26							+ scanner.findInLine( 
27									Pattern.compile(".....for"))); 
28
29			// close the scanner 
30			scanner.close(); 
31		} 
32		catch (IllegalStateException e) { 
33			System.out.println("Exception thrown : " + e); 
34		} 
35	} 
36} 
37