Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串数组,称为食物, 其中
food[0] = "banana fruit" food[1] = "potato vegetable" food[2] = "peas vegetable" food[3] = "apple fruit" food[4] = "pumpkin vegetable"
我如何只打印蔬菜?
您可以使用其中一个endsWith()或contains()String 方法:
endsWith()
contains()
for (String s : food) { if (s.endsWith("vegetable")) System.out.println(s); }