code_junkie

how to find words within a range in a TreeSet<String> using regular expressions (java)

Nov 12th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. while (it.hasNext()) {
  2. System.out.println(it.next());
  3. }
  4.  
  5. after
  6. explorers
  7. giant
  8. hoping
  9. internet
  10. into
  11. .
  12. .
  13. .
  14. virtual
  15. world
  16.  
  17. String pattern = "[^m-z]";
  18.  
  19. "^[m-z]"
  20.  
  21. wordSet.tailSet("m", true);
  22.  
  23. wordSet.subSet("b", true, "z", false);
  24.  
  25. while (it.hasNext()) {
  26. String element = it.next();
  27. if (element.toLowerCase().matches("^[m-z].*")) {
  28. System.out.println(element);
  29. }
  30. }
  31.  
  32. while (it.hasNext()) {
  33. String element = (String) it.next();
  34. char c = element.charAt(0);
  35. if (c >= 'm' && c <= 'z') {
  36. System.out.println(element);
  37. }
  38. }
Add Comment
Please, Sign In to add comment