in

Scanner Class with Delimiters Example in Java


Scanner is an important class for accepting input in Java. In the sample code below, we seek to illustrate how to use delimiters when scanning input. This method can be used in predefined cases where you know the data and delimiters that you are getting.

*/

import java.util.Scanner;

public class DelimiterInScanner{
	
	public static void main(String[] args) 
	{  
		DelimiterInScanner delimiterInScanner = new DelimiterInScanner();
		delimiterInScanner.proceed();
	}

	public void proceed()
	{
		String deLimiterString = "deLimiter" ;
		String inputString = "1 deLimiter ABC Corp. deLimiter $55 deLimiter";
		
		Scanner scanner = new Scanner(inputString).useDelimiter("s*"+deLimiterString+"s*");
		
		System.out.println(scanner.nextInt());
		System.out.println(scanner.next());
		System.out.println(scanner.next());
		
		scanner.close(); 
	}
		
}

/*

Here is the output you can expect when running this code:

 

[[email protected]]# java DelimiterInScanner
1
ABC Corp.
$55

Read more Java programming tutorials.



Source: https://www.developer.com/java/scanner-class-java/

Trying to get pagination in my website Spring-boot

How to upload a JSON that includes an image file to a Spring Boot Rest API