Last active
September 12, 2017 13:42
-
-
Save hectormethod/31ec4fc830b49e88549660f37af1da0c to your computer and use it in GitHub Desktop.
[PeekableScanner] #java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class PeekableScanner | |
{ | |
private Scanner scan; | |
private String next; | |
public PeekableScanner( String source ) | |
{ | |
scan = new Scanner( source ); | |
next = (scan.hasNext() ? scan.next() : null) | |
} | |
public boolean hasNext() | |
{ | |
return (next != null); | |
} | |
public String next() | |
{ | |
String current = next; | |
next = (scan.hasNext() ? scan.next() : null) | |
return current; | |
} | |
public String peek() | |
{ | |
return next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment