Reputation: 663
In below code i am getting all elements from the list and splitting the text after "("
.
for (WebElement element : measureKeys) {
String[] measure = element.getText().split("\\(");
testing.add(measure[0])
}
How to use lambdas for above code
Upvotes: 1
Views: 2601
Reputation: 1410
Another alternative is ,
List<String> list= Pattern.compile("\\(")
.splitAsStream(measureKeys)
.collect(Collectors.toList());
Upvotes: 1
Reputation: 81
List<String> measureKeys = new ArrayList<>();
List<String> a = new ArrayList<>();
measureKeys.forEach(element -> a.add(element.split("\\(")[0]));
Is that your wish ?
Upvotes: 0
Reputation: 311893
You could essentially turn the body of the loop to a lambda expression and collect the the results
List<String> testing =
measureKeys.stream()
.map(e -> element.getText().split("\\(")[0])
.collect(Collectors.toList());
Upvotes: 8