JavaScanner Class with Delimiters Example in Java

Scanner Class with Delimiters Example in Java content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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:


[root@mypc]# java DelimiterInScanner
ABC Corp.

Read more Java programming tutorials.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories