fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Collections;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. ArrayList<String> list = new ArrayList<>();
  14. list.add("19.15.15.90:61234");
  15. list.add("19.15.15.29:28010");
  16. list.add("19.15.15.80:8998");
  17. list.add("19.15.15.102:8998");
  18. list.add("25.25.24.15:8998");
  19. list.add("25.25.24.80:8998");
  20. list.add("210.192.38.25:8998");
  21. list.add("210.192.38.29:8998");
  22.  
  23. // You should sort the list
  24. Collections.sort(list);
  25.  
  26. // may aswell print the first one
  27. System.out.println(list.get(0));
  28. for (int i = 1; i < list.size(); i++) {
  29. int pos = nthIndexOf(list.get(i), '.', 3);
  30. if (!list.get(i).substring(0, pos).equals(list.get(i - 1).substring(0, pos))) {
  31. System.out.println(list.get(i));
  32. }
  33. }
  34. }
  35.  
  36. public static int nthIndexOf(String text, char needle, int n) {
  37. for (int i = 0; i < text.length(); i++) {
  38. if (text.charAt(i) == needle) {
  39. n--;
  40. if (n == 0) {
  41. return i;
  42. }
  43. }
  44. }
  45. return -1;
  46. }
  47. }
Success #stdin #stdout 0.08s 27956KB
stdin
Standard input is empty
stdout
19.15.15.102:8998
210.192.38.25:8998
25.25.24.15:8998