• Source
    1. /* package whatever; // don't place package name! */
    2.  
    3. import java.util.*;
    4. import java.util.regex.*;
    5. import java.io.*;
    6.  
    7. /* Name of the class has to be "Main" only if the class is public. */
    8. class Ideone
    9. {
    10. public static void main(String[] args) {
    11. // This is a source string example
    12. StringReader stringReader = new StringReader("\"field_name\":\"field_value\"");
    13. // The scanner instance with default values
    14. Scanner scanner = new Scanner(stringReader);
    15. // Set the scanner delimiter to \b* so it takes blanks as delimiters only if they're there
    16. scanner.useDelimiter(Pattern.compile("\b*"));
    17.  
    18. while (scanner.hasNext()) {
    19. System.out.print(scanner.next());
    20. }
    21. }
    22. }