简体   繁体   English

如何获取列表中特定对象的计数?

[英]how to get the count of particular object in a List?

i want to get the count of the particular object in List我想获取 List 中特定对象的计数

AgentSumBeans obj=new AgentSumBeans();
            while(rs.next())
            {

                obj.setIrctcIdCreatedDate(rs.getString(1)); 
                obj.setIsevaProOpted(rs.getString(2));

            }
          list.add(obj);// first object

AgentSumBeans obj2=null;
            while(rs3.next())
            { 
                obj2=new AgentSumBeans();
            obj2.setAmonthyear(rs3.getString(1));
            obj2.setAnoOfTkts(rs3.getInt(2));
            obj2.setAbookingAmount(rs3.getInt(3));
            obj2.setAavgAmount(rs3.getInt(4));
            obj2.setAperDayTkts(rs3.getInt(5));

            list.add(obj2);// i will be getting more than one object here

            }  

how to find how many obj2 objects got created ?如何找到创建了多少obj2对象?

Try to replace while loop to for loop with counter - and it's the simplest solution, i think.尝试用计数器替换while循环到for循环 - 我认为这是最简单的解决方案。

Or create counter before while loop.或者在while循环之前创建计数器。

从列表中获取 Object<object> 如果 Object 中的特定字段与单独列表中的任何值匹配<div id="text_translate"><p>我有一个字符串列表,其中包含所有商店编号:</p><pre> List&lt;String&gt; stores = new ArrayList&lt;&gt;;</pre><p> 还有一个对象列表,例如:</p><pre> List&lt;UserStores&gt; userStores = new ArrayList&lt;&gt;;</pre><p> 现在,这个 UserStores class 看起来像这样:</p><pre> public class UserStores { private String storeNo; private String storeName; private String country; }</pre><p> 如果上面给出的“商店”列表中存在任何 storeNo,我想从此List&lt;UserStores&gt;中获取所有用户商店。</p><p> 例如,</p><pre> stores = {1,2}; UserStores = [ {2, qwe, wqew}, {1,ABC, India}, {3, asd, USA} ]; expected result = [{1,ABC, India}, {2, qwe, wqew}]; in the order of stores present in 'stores' list,</pre><p> 我怎样才能使用流/收集器得到这个?</p><p> 我当前的代码是这样的……可以改进吗?</p><pre> private static List&lt;UserStores&gt; getModifiedUserStoresList( List&lt;String&gt; stores, List&lt;UserStores&gt; userStores ) { List&lt;UserStores&gt; userStoreList = new ArrayList&lt;&gt;(); for(int i = 0; i &lt; stores.size(); i++) { for(int j = 0; j &lt; userStores.size(); j++) { if(userStores.get(j).getStoreNo().equals(stores.get(i))) { userStoreList.add(userStores.get(j)); break; } } } return userStoreList; }</pre></div></object> - Get Object from List<Object> if a particular field in Object matches any value from a separate list

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取列表中特定索引中的项目总数 <object> ? - How to get total items count in specific index of List<object>? 如何使用 mongoTemplate 检索特定列表 object? - How to retrieve a particular list object using mongoTemplate? 对象列表 - 获取对象字段的不同计数 - List of objects - get object fields distinct count 如何使用 Hibernate 遍历对象列表并获取特定 object 的 Id - How to iterate through list of objects and get Id of particular object using Hibernate 如何获得此示例的对象的特定值 - How to get a particular value of an object of this example 如何获取DateTime对象的特定部分? - How to get particular parts of a DateTime object? 如何获取我的对象的特定属性? - How to get a particular attribute of my object? 如何在java中获取List中的特定元素? - How to get to a particular element in a List in java? Java 8:如何在不将流转换回列表并在第 0 个位置获取值的情况下获取列表内对象中的特定值? - Java 8: How to get particular value within object inside list without converting stream back to list and fetch value at 0th location? 从列表中获取 Object<object> 如果 Object 中的特定字段与单独列表中的任何值匹配<div id="text_translate"><p>我有一个字符串列表,其中包含所有商店编号:</p><pre> List&lt;String&gt; stores = new ArrayList&lt;&gt;;</pre><p> 还有一个对象列表,例如:</p><pre> List&lt;UserStores&gt; userStores = new ArrayList&lt;&gt;;</pre><p> 现在,这个 UserStores class 看起来像这样:</p><pre> public class UserStores { private String storeNo; private String storeName; private String country; }</pre><p> 如果上面给出的“商店”列表中存在任何 storeNo,我想从此List&lt;UserStores&gt;中获取所有用户商店。</p><p> 例如,</p><pre> stores = {1,2}; UserStores = [ {2, qwe, wqew}, {1,ABC, India}, {3, asd, USA} ]; expected result = [{1,ABC, India}, {2, qwe, wqew}]; in the order of stores present in 'stores' list,</pre><p> 我怎样才能使用流/收集器得到这个?</p><p> 我当前的代码是这样的……可以改进吗?</p><pre> private static List&lt;UserStores&gt; getModifiedUserStoresList( List&lt;String&gt; stores, List&lt;UserStores&gt; userStores ) { List&lt;UserStores&gt; userStoreList = new ArrayList&lt;&gt;(); for(int i = 0; i &lt; stores.size(); i++) { for(int j = 0; j &lt; userStores.size(); j++) { if(userStores.get(j).getStoreNo().equals(stores.get(i))) { userStoreList.add(userStores.get(j)); break; } } } return userStoreList; }</pre></div></object> - Get Object from List<Object> if a particular field in Object matches any value from a separate list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM