Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] d) {
- // this is not a complete test
- String input = "This iS a test. NoThing more. 噴 for exAmple";
- ArrayList<String> result = new ArrayList<>();
- int length = input.length();
- // we will split the input into a sequence of sections, each which end when
- // we go lower case to upper case
- int start = 0;
- // pointer is which character we are checking
- int pointer = start;
- while (pointer < length - 1) // go through input
- {
- char thisChar = input.charAt(pointer);
- char nextChar = input.charAt(pointer + 1);
- if (Character.isLowerCase(thisChar) && Character.isUpperCase(nextChar)) { // found a new section
- String sub = input.substring(start, pointer + 1);
- result.add(sub);
- start = pointer + 1;
- }
- pointer++; // move on
- }
- // need to add final section
- String sub = input.substring(start, length);
- result.add(sub);
- for (String s : result) {
- System.out.println(s);
- }
- }
- output:
- This i
- S a test. No
- Thing more. 噴 for ex
- Ample
Advertisement
Add Comment
Please, Sign In to add comment