fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  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) throws java.lang.Exception
  11. {
  12. String example = " sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode\n" +
  13. " 0: 00000000:04D2 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 15662 1 ffff8800baf1c780 100 0 0 10 0\n" +
  14. " 1: 00000000:04D2 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 15662 1 ffff8800baf1c780 100 0 0 10 0";
  15.  
  16. Scanner scanner = new Scanner(example);
  17. scanner.useRadix(16).useDelimiter("[\\s:]+");
  18. Set<Integer> result = new HashSet<>();
  19. scanner.next();
  20.  
  21. while (scanner.hasNextLine()) {
  22. String skipped = scanner.nextLine();
  23. System.out.println("Skipped: " + skipped); // skip header on first iteration and also skips remainder of previous line after we read the int
  24. if (scanner.hasNextInt()) {
  25. int slot = scanner.nextInt();
  26. System.out.println(slot);
  27. } else {
  28. System.out.println("No int avaialble");
  29. }
  30. }
  31.  
  32. System.out.println("Done");
  33. }
  34. }
Success #stdin #stdout 0.07s 711680KB
stdin
Standard input is empty
stdout
Skipped:   local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
0
Skipped: : 00000000:04D2 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 15662 1 ffff8800baf1c780 100 0 0 10 0
1
Skipped: : 00000000:04D2 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 15662 1 ffff8800baf1c780 100 0 0 10 0
No int avaialble
Done