开发者

Compare data in two arraylist and do update in java

I am new to java and I would like to know if it is possi开发者_如何学运维ble to do the following:

I have two different list of array

List A

1111,A,B,C  
1111,E,E,F  
1111,Z,Z,Z  
2222,C,D,E  
4444,E,E,E  
.....  

List B

1111,123,N  
2222,222,Y  
3333,333,N   
4444,444,N  
.....

So basically, List A will have duplicate value in column 1.

What I would like to do is to

  1. Search List B using column 1 data from List A. After it finds a row in List B that matches the data (i.e. 1111), it updates List B, column 3 with a certain value (i.e.N).

  2. Later on when I process List B, depending on the value in column 3 for each row, I know I need to go to List A to get the data.

Now I would like to know how I can do it? Also, when I do #2 above, there are duplicate rows for one value (i.e. 1111), how can I make sure I have got all data?

Any suggestions are greatly appreciated.

Thanks


Iterate through A putting the column 1 values into a HashSet.

Next, iterate through B and set the value of column 3 to be whether or not your HashSet contains the value in column 1 (of B).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜