the task is to store consecutive characters in a List. Main with Input/Output looks like this:
public static void main(String[] args) {
List<String> blocks = blocks("Hello faaantastic world");
System.out.println(blocks); // => ["ll", "aaa"]
System.out.println(blocks("aaabccdeeeefaaa")); // => ["aaa", "cc", "eeee", "aaa"]
System.out.println(blocks("This is an example")); // => []
System.out.println(blocks("Another example ...")); // => [" ", "..."]
System.out.println(blocks("")); // => []
My method looks like this:
public static LinkedList<String> blocks(String s) {
LinkedList<String> list = new LinkedList<>();
String word = "";
for(char c : s.toCharArray()) {
if (c == ??) {
}
}
return list;
the String word is used to store consecutive letters. I found the toCharArray, to split each character of the String. But I have a problem with the if-block. If I do c == c+1 to check I and the following character of I, it's not working...I don't know how to solve this problem. Can someone help me? trying to solve it for 2 days now...