Skip to content

Instantly share code, notes, and snippets.

@hectormethod
Last active September 12, 2017 13:42
Show Gist options
  • Save hectormethod/31ec4fc830b49e88549660f37af1da0c to your computer and use it in GitHub Desktop.
Save hectormethod/31ec4fc830b49e88549660f37af1da0c to your computer and use it in GitHub Desktop.
[PeekableScanner] #java
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