简体   繁体   English

根据条件显示列表对象的数据

[英]Display Data from List object based on condition

Can someone please assist on how to get the data from the below List based on user input value. 有人可以协助您如何根据用户输入值从下面的列表中获取数据。 I have mentioned the List records and the output data how its required to be displayed.. Appreciate if someone can help with details. 我已经提到了List记录和输出数据如何显示。需要感谢有人可以提供详细信息。

 **List< Object > alist** **==>** clouds={all=88}, coord={lat=32.16329, lon=12.52859},, **name**=Yafran, rain={3h=0.255}, weather=({description=light rain, icon=10d, id=500, main=Rain}), wind={deg=356.5, speed=3.96}}
clouds={all=89}, coord={lat=42.06329, lon=12.52859},, **name**=Pheonix, rain={3h=0.255}, weather=({description=heavy rain, icon=10d, id=500, main=Rain}), wind={deg=356.5, speed=3.96}}
clouds={all=96}, coord={lat=12.06329, lon=12.52859},, **name**=Atlanda, rain={3h=0.255}, weather=({description=light rain, icon=10d, id=500, main=Rain}), wind={deg=356.5, speed=3.96}}

I want output from this list based on user input… say if user enter **name** : **Yafran**, I should display the details in my UI as below.
**Name** : Yafran
**Weather. Description** = light rain
**Wind.speed** = 3.96
**Wind.deg**=356.5
**Coord.lat**=32.12

I have n records in the list and the data should fetch the corresponding row from the list of objects based on user input. 我在列表中有n条记录,数据应根据用户输入从对象列表中提取相应的行。

If you have a list and you want to search based on some key .Two solution possible 如果您有一个列表,并且想要基于某个键进行搜索。可能有两种解决方案

1.Iterate over list and match one by one with key If present return the result. 1.遍历列表并与键一一对应如果存在则返回结果。

2.If your key is in sorted order you can use binary search. 2.如果您的密钥按排序顺序,则可以使用二进制搜索。

One thing If you are only want use single key you can use HashMap complexity of search is constant. 一件事如果您只想使用单个键,则可以使用HashMap进行搜索,其复杂性是恒定的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM