把集合中以“API”结尾的元素查找出来并组成一个新的集合
public class Demo3 {
public static void main(String[] args) {
// 把features集合中以“API”结尾的元素查找出来并组成一个新的集合
List<String> features = Arrays.asList("Lambdas", "Default Method", "Stream API", "Stream API", "Date and Time API");
ArrayList<String> list = new ArrayList<String>();
for (String strs : features) {
char[] cs2 = strs.toCharArray();
if (cs2[cs2.length-1]=='I'&&cs2[cs2.length-2]=='P'&&cs2[cs2.length-3]=='A'){
list.add(strs);
}
}
for (String str:list
) {
System.out.println(str);
}
}
}