BAEL-865 - updated example code (#2029)

* added project files for evaluation article by smatt382@gmail.com

* added project files for evaluation article by smatt382@gmail.com

* added class com.baeldung.string.StringToCharStream by smatt382@gmail.com

* updated the example codes. Use assert statements

* updated example codes

* fixed conflict in pom.xml

* remove redundant files'

* added unit test
This commit is contained in:
Seun Matt
2017-06-09 13:32:20 +01:00
committed by Zeger Hendrikse
parent f18c993d71
commit 920167f5b7
11 changed files with 609 additions and 360 deletions

View File

@@ -0,0 +1,46 @@
package com.baeldung.string;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Created by smatt on 26/05/2017.
*/
public class StringToCharStream {
public StringToCharStream() {
//let's use the Stream API to manipulate a string
//this will count the occurrence of each character in the test string
System.out.println("Counting Occurrence of Letter");
String testString = "Noww";
//we don't want to use foreach, so . . .
Map<Character, Integer> map = new HashMap<>();
testString.codePoints()
.mapToObj(c -> (char) c)
.filter(c -> Character.isLetter(c))
.forEach(c -> {
if(map.containsKey(c)) {
map.put(c, map.get(c) + 1);
} else {
map.put(c, 1);
}
});
//printing out the result here
System.out.println(map.toString());
}
public static void main(String [] args) {
new StringToCharStream();
}
}