在Arraylist中搜索Arraylist。 [英] Search Arraylist in Arraylist.

查看:90
本文介绍了在Arraylist中搜索Arraylist。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个包含{0,1,2,3,4,5,9,8,7}的arraylist A1

我有另一个arraylist A2包含{4,5,9}


我想搜索A1中是否存在A2并且可能返回

首次出现指数。有人可以就此提出建议吗?


谢谢,

Simon

Hi all,

I''ve an arraylist A1 that contains {0,1,2,3,4,5,9,8,7}
I''ve another arraylist A2 that contains {4,5,9}

I would like to search whether if A2 is present in A1 and maybe return the
first occurance index. Can anyone advise on this?

Thanks,
Simon

推荐答案

西蒙,


我会使用这种方法。

http://msdn2.microsoft.com/en-us/lib...t.indexof.aspx


我希望这会有所帮助,


Cor
Simon,

I would use this method.

http://msdn2.microsoft.com/en-us/lib...t.indexof.aspx

I hope this helps,

Cor


Cor,


我试过这个,但似乎没有工作。我认为这个函数

的作用是它搜索我的A1中的每个项目以获得完整匹配

的整个A2。也就是说:


A1中的项目:A2中的项目:

0 {4,5,9}

1

2

3

4

5

9

8

7


它搜索A1中的每个项目以获得{4,5,9}的arraylist。相反,我需要

类似


A1中的项目:A2中的项目:

0 4

1 5

2 9

3

4

5

9

8

7


对不起,我不能解释得太好,但还有其他方法吗?
< br $>
- 西蒙


" Cor Ligthert [MVP]" <无************ @ planet.nl>在消息中写道

news:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
Cor,

I''ve tried this but doesn''t seem to be working. I think what this function
does is that it searches through each items in my A1 for the exact matches
of the whole of A2. That is to say:

Items in A1: Items in A2:
0 {4,5,9}
1
2
3
4
5
9
8
7

It searches each items in A1 for an arraylist of {4,5,9}. Instead, I need
something like

Items in A1: Items in A2:
0 4
1 5
2 9
3
4
5
9
8
7

Sorry I can''t explain too well, but any other ways?

--Simon

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Simon,

我会用这种方法。

http://msdn2.microsoft.com/en-us/lib...t.indexof.aspx

我希望这有帮助,

Cor
Simon,

I would use this method.

http://msdn2.microsoft.com/en-us/lib...t.indexof.aspx

I hope this helps,

Cor



Simon Says写道:
Simon Says wrote:
大家好,

我有一个包含{0,1,2,3,4,5,9,8,7}的arraylist A1
我有另一个包含{4,5的arraylist A2 ,9}

我想搜索A1中是否存在A2并且可能返回第一个出现指数。有人可以就此提出建议吗?
Hi all,

I''ve an arraylist A1 that contains {0,1,2,3,4,5,9,8,7}
I''ve another arraylist A2 that contains {4,5,9}

I would like to search whether if A2 is present in A1 and maybe
return the first occurance index. Can anyone advise on this?




您是说A1和A2中的元素是唯一的还是有序的?是

A1和A2是多么微不足道?


如果计数(A2)>计数(A1)则不匹配

获取A2的第一个元素并在A1中找到它

检查A1中是否有足够的元素可以进行匹配

获取A2的后续元素并将它们与后续元素进行比较A1的元素

Andrew



Are you saying that the elements in A1 and A2 are unique and in order? Are
A1 and A2 of trivial length?

if count(A2)>count(A1) then no match
take first element of A2 and find it in A1
check there are enough elements remaining in A1 for a match to be possible
take subsequent elements of A2 and compare them to subsequent elements of A1

Andrew


这篇关于在Arraylist中搜索Arraylist。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆