Q: Java Scanner next() scanning in empty tokens I'm trying to use a scanner to split up an IP address (String) into 4 ints. I used a delimiter and set the pattern to "." 
next() Documentation:

Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext() returned true.

I initially tried using the IP String with no periods at the ends but I have now tried adding periods to each end of the string. Scanner next() still does not scan my numbers (or anything).
public void setIP(String ip){
    IPstring = "."+ip+".";
    Scanner sc = new Scanner(IPstring);
    sc.useDelimiter(".");
    System.out.println(IPstring);
    System.out.println(sc.next());
    System.out.println(sc.next());
    System.out.println(sc.next());
    sc.close();
}

Output:
.216.198.240.0.

Note: there are 3 blank lines under .216.198.240.0.
I intend to replace the printlns with:
IP1 = Integer.parseInt(sc.next());
IP2 = Integer.parseInt(sc.next());
IP3 = Integer.parseInt(sc.next());
IP4 = Integer.parseInt(sc.next());

IP1-4 are ints representing the 4 parts of the IP address.

A: The delimiter is a regular expression.
Use
sc.useDelimiter("\\.");

