Find the words having more than 5 character and convert them to capital letters?
There are following way to find the words having more than 5 character and convert them to capital letters using java8.
- First convert string Arrays to list using Arrays.asList() method.
- Now get the Stream data from List using arrayList.stream() method.
- Inside filter call the r.length() to check which string length is greater than 5.
- In map use toUpperCase() method converts a string to upper case letters.
- Now call the Collectors.toList() to store all string inside list.
- Now print the words.
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class FindWord {
public static void main(String[] args) {
String[] strArray = { "Mumbai", "Delhi", "chennai", "pune", "punjab", "goa" };
List<String> str = Arrays.asList(strArray).stream().filter(r -> r.length() > 5).map(String::toUpperCase)
.collect(Collectors.toList());
System.out.println("words are :- " + str);
}
}
Output :-
words are :- [MUMBAI, CHENNAI, PUNJAB]
Find the words having more than 5 character and convert them to capital letters? Read More »