2015-07-22 60 views
-2

假设我添加4个对象:如何从对象列表中计算具有特定条件的对象?

对象1串 “早晨”

对象2串 “午”

对象3串 “黄昏”

对象4用字符串“早上”

如何计算列表中有“早”字符串的对象的数量?

+0

欢迎使用计算器。只需访问我们的[旅游](http://stackoverflow.com/tour)页面以获取更多信息以使用本网站。 – Aradhya

+0

该网站的问题应该是关于特定的编程问题。当你有代码不工作,因为它应该在这里发布它。你到底有什么困难? –

回答

1
int count = 0; 
    for (String s : stringList ){ 
     if(s.equals("Morning")){ //s.equalsIgnoreCase(Morning) or s.contains("Morning") 
      count++; 
     } 
    } 
    System.out.println("count = "+count); 
相关问题