JavaScanner Class with Delimiters Example in Java

Scanner Class with Delimiters Example in Java

Java Developer Tutorials

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();

	public void proceed()
		String deLimiterString = "deLimiter" ;
		String inputString = "1 deLimiter ABC Corp. deLimiter $55 deLimiter";
		Scanner scanner = new Scanner(inputString).useDelimiter("\\s*"+deLimiterString+"\\s*");


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


[[email protected]]# java DelimiterInScanner
ABC Corp.

Read more Java programming tutorials.

Latest Posts

Related Stories