2014-07-03 69 views
0

另一個名單上有兩個列表List<List<Integer>> a和b,如下:檢查清單中包含的Java

a = [[120, 0], [121, 1], [122, 2], [123, 3], [124, 4], [125, 5]] 
b = [[123, 3]] 

我想要一個簡單的方法返回如果b包含元素a

我試過b.contains(a)!Collections.disjoint(a, b),但無濟於事。它似乎不適用於這樣深的名單。

編輯:我張貼了我的問題的全碼:

一些私有變量:

private List<List<Integer>> processedCurrentCoordinate = new ArrayList<List<Integer>>(); 

而主菜(我只希望如果包括HurdlefullCoordinatesList要處理的第一循環裏面this.processedCurrentCoordinate

public List<Integer> getNewData(int oldPositionX, int oldPositionY, int hasFood, List<List<Integer>> HurdlefullCoordinatesList) { 

do { 
    do { 
    this.currentCoordinate.clear(); 
    this.processedCurrentCoordinate.clear(); 
    this.newPositionX = this.modelAnt.randomposition(oldPositionX); 
    this.newPositionY = this.modelAnt.randomposition(oldPositionY); 
    this.currentCoordinate.add(newPositionX); 
    this.currentCoordinate.add(newPositionY); 
    this.processedCurrentCoordinate.add(currentCoordinate); 
    } while((Integer.valueOf(this.newPositionX).equals(Integer.valueOf(oldPositionX))) && (Integer.valueOf(this.newPositionY).equals(Integer.valueOf(oldPositionY)))); 
} while(HurdlefullCoordinatesList.contains(this.processedCurrentCoordinate)); 
+0

向我們展示您的嘗試。這取決於'List'和它包含的元素的實現。 –

+0

對不起,它似乎是一個自動消息。我正在更新這個問題。 – sidney

+0

看看這一個:http://stackoverflow.com/questions/24035133/need-algorithm-for-fast-storage-and-retrieval-search-of-sets-and-subsets/24296615#24296615 – aa333

回答

0

您應該使用內部列表作爲參數,包含和不相交?