我想重构下面的代码以利用 Stream() 方法,但不知道如何去做。鉴于变量句子是一个字符串列表,并预先填充了:“杰克去公园”、“玛丽呆在家里”、“克里斯去上班”我将如何使用 Stream() 返回包含“home”一词的整行List<String> sentences = new ArrayList<>();sentences.add("Jack went to the park");sentences.add("Mary stayed home");sentences.add("Chris went to work");for (int I=0; I < sentences.size(); I++) { if (sentences.get(I).contains("home")) { return sentences.get(I); }}
添加回答
举报
0/150
提交
取消