waltermilner

Untitled

Jun 28th, 2019
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. public static void main(String[] d) {
  2.     // this is not a complete test
  3.     String input = "This iS a test. NoThing more. 噴 for exAmple";
  4.     ArrayList<String> result = new ArrayList<>();
  5.     int length = input.length();
  6.     // we will split the input into a sequence of sections, each which end when
  7.     // we go lower case to upper case
  8.     int start = 0;
  9.     // pointer is which character we are checking
  10.     int pointer = start;
  11.     while (pointer < length - 1) // go through input
  12.     {
  13.       char thisChar = input.charAt(pointer);
  14.       char nextChar = input.charAt(pointer + 1);
  15.       if (Character.isLowerCase(thisChar) && Character.isUpperCase(nextChar)) { // found a new section
  16.         String sub = input.substring(start, pointer + 1);
  17.         result.add(sub);
  18.         start = pointer + 1;
  19.       }
  20.       pointer++; // move on
  21.     }
  22.     // need to add final section
  23.     String sub = input.substring(start, length);
  24.     result.add(sub);
  25.     for (String s : result) {
  26.       System.out.println(s);
  27.     }
  28.  
  29.   }
  30. output:
  31. This i
  32. S a test. No
  33. Thing more. 噴 for ex
  34. Ample
Advertisement
Add Comment
Please, Sign In to add comment