0

这是字符串的一部分

471 pfm9254-disk01_01                                       0           io_grp0       online 3            Chassis2_IBMi       100.00GB  striped 0     fcmap0                60050768028080EF6400000000001391 1            1          empty            0             no        0                     
472 IP10-32-41-70_SLES11SP2_10G                             0           io_grp0       online 0            pfm3079_pfm3128     10.00GB   striped                             60050768028080EF64000000000007CE 0            1          empty            0             no        0                     
473 pfm3128_pva1091_stgvios1                                0           io_grp0       online 1            VIOS_StgPool        35.00GB   striped                             60050768028080EF64000000000007D1 0            1          not_empty        0             no        0                     
474 vdisk64                                                 0           io_grp0       online 13           pfm9253_pfm9254_new 9.94GB    striped                             60050768028080EF6400000000001CC4 0            1          empty            0             no        0                     
475 vdisk65                                                 0           io_grp0       online 13           pfm9253_pfm9254_new 10.00GB   striped                             60050768028080EF6400000000001CC6 0            1          empty            0             no        0                     

我想检查它是否包含我的 arrayList 的任何成员

我知道我可以遍历arrayList,然后检查每个元素字符串是否包含该元素。我正在寻找一个有效的解决方案

这是我的数组列表

ArrayList<String> volIDsSent = new ArrayList<String>();
volIDsSent.add("60050768028080EF6400000000000AC3");
volIDsSent.add("60050768028080EF6400000000000FF8");

我会逐行从某处获取字符串。

4

2 回答 2

1

考虑读取一次数组并通过连接“|”来构建一个正则表达式字符串 在每个之间,手动或使用 StringUtils.join 之类的东西。然后对每一行使用正则表达式来读取。

于 2013-10-24T13:23:13.790 回答
0

If you want to check if one of the Strings in your ArrayList is a substring of your big String, you will have to iterate over the ArrayList and break if you find one occurence (if you really just want to know IF there is one ore more).

It cannot get more efficient because you need to check all of them as long as you havent found any occurence.

于 2013-10-24T13:16:18.127 回答