简体   繁体   English

Java获取数组列表中两个元素之间的元素子列表

[英]Java Get Sub List of Elements between two elements in arraylist

I have below data in arrayList. 我在arrayList中有以下数据。 Every row is an element in arraylist. 每行都是arraylist中的一个元素。

How can I get/map for every Service corresponding description Example 1: {Service= Review of Inpatient Hospital Care,Description= When your condition requires you to be an inpatient Description= If payment determination criteria are not met. 我如何获取/映射每个服务的对应描述示例1:{服务=住院医院护理检查,描述=当您的病情要求您是住院病人时描述=如果不符合付款确定标准。 If we inform you that you do not meet payment determination criteria.} 如果我们通知您您不符合付款确定标准。}

Example 2: {Service= Ambulatory Surgical Center (ASC),Description= When your condition requires you to be an inpatient Description= Covered, including operating rooms, surgical supplies.} 示例2:{服务=门诊手术中心(ASC),说明=当您的病情要求您作为住院病人时说明==承保,包括手术室,外科用品。}

Service= Review of Inpatient Hospital Care
Description= When your condition requires you to be an inpatient
Description= If payment determination criteria are not met. 
If we inform you that you do not meet payment determination criteria. 
Service= Ambulatory Surgical Center (ASC)
Description= Covered, including operating rooms, surgical supplies.
Service= Hospital Ancillary Services
Description= Covered, including surgical supplies, hospital anesthesia services.
Service= Hospital Room and Board
Description= Covered, including:Semi-Private Rooms.  If you are hospitalized at a participating facility.
Description= Private Rooms.At Participating Hospitals.
Description= At Nonparticipating Hospitals:
Description= Newborn nursery care. Covered for the baby's nursery care after birth.
Description= Please note: Services at nonparticipating and out-of-state post-acute.
Service= Intensive Care Unit/Coronary Care Unit.
Description= Covered.
Service= Intermediate Care Unit
Description= Covered.
Service= Isolation Care Unit
Description= Covered.

I assume you want to create new objects that contain every data for each Service encountered, containing two properties : service and description. 我假设您要创建一个新对象,其中包含遇到的每个Service的每个数据,其中包含两个属性:service和description。 Am I right ? 我对吗 ?

In that case, you can iterate over all the elements and each time you find a line starting with 'Service=', you instanciate a new object with the content of the line after 'Service='. 在这种情况下,您可以遍历所有元素,并且每次找到以'Service ='开头的行时,都可以实例化一个新对象,并在'Service ='之后加上该行的内容。 You can do this with regluar expressions . 您可以使用regluar表达式执行此操作 Each instanciated object should be put in another list or map. 每个实例化的对象都应放在另一个列表或映射中。

Then, the next lines which doesn't start with 'Service=' will be concatenate in the 'Description' property of the current new object. 然后,以下不以“ Service =”开头的行将串联在当前新对象的“描述”属性中。

At the end of the loop, you would have a new list containg objects filled with all your data. 在循环的最后,您将拥有一个包含所有数据填充的对象的新列表。

Edit : I would have made a Service classe with two properties : name and description, both as String. 编辑:我将使服务类具有两个属性:名称和描述,都作为String。

Then, when you loop over the raw data list, each time you get a 'Service' line, you create a new Service with its name, extracted from the current line. 然后,当您遍历原始数据列表时,每次获得“服务”行时,都将创建一个新服务,其名称将从当前行中提取。

Next lines will be added to your buffer (I recommend the StringBuilder class in a single Thread program without synchronization), as the description value. 接下来的行将作为描述值添加到缓冲区中(我建议在不同步的单个Thread程序中使用StringBuilder类 )。

Finally, when you find a new Service line, you begin with flushing the buffer into the previous Service instance, filling its description property. 最后,找到新的Service行时,首先将缓冲区刷新到先前的Service实例中,并填充其description属性。 And then you can start a new iteration by creating a new Service instance and loop again. 然后,您可以通过创建新的Service实例来开始新的迭代并再次循环。

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

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