@Test public void givenJsonArray_shouldFilterAllTopicsStartingCToList() throws Exception { Java8Integration java8Integration = new Java8Integration(); List<String> topics = java8Integration.filterJsonArrayToList(); assertThat(topics).contains("Cloud"); assertThat(topics).contains("Cognitive"); }
public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; } }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; }  }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; }  List<String> filterJsonArrayToList(); JsonArray filterJsonArrayToJsonArray(); }
Java8Integration extends JsonExample { public List<String> filterJsonArrayToList() { List<String> topics = jsonObject.getJsonArray("topics").stream() .filter(jsonValue -> ((JsonString) jsonValue).getString().startsWith("C")) .map(jsonValue -> ((JsonString) jsonValue).getString()) .collect(Collectors.toList()); return topics; }  List<String> filterJsonArrayToList(); JsonArray filterJsonArrayToJsonArray();  }