0

I have two Lists List<List<Integer>> a and b, as following:

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

I want a simple method that returns true or false if b contains an element ofa.

I tried b.contains(a), and !Collections.disjoint(a, b), but to no avail. It doesn't seem to work with such deep lists.

EDIT: I'm posting the full code of my issue:

Some private variables:

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

And the main dish ( I want the first loop to be processed only if HurdlefullCoordinatesList is included inside 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));
sidney
  • 2,704
  • 3
  • 28
  • 44
  • Show us what you tried. This depends on the implementation of the `List` and the elements it contains. – Sotirios Delimanolis Jul 03 '14 at 00:57
  • Sorry, it seemed to be an automatic message. I'm updating the question. – sidney Jul 03 '14 at 00:57
  • Take a look at this one: http://stackoverflow.com/questions/24035133/need-algorithm-for-fast-storage-and-retrieval-search-of-sets-and-subsets/24296615#24296615 – aa333 Jul 03 '14 at 00:58
  • [Here's an example that works.](https://ideone.com/AWfLiE) Remember that lists are ordered. – Sotirios Delimanolis Jul 03 '14 at 00:58
  • Thanks you, I studied it, but I can't understand it unfortunately. I'll try harder. Between, I updated my question. – sidney Jul 03 '14 at 01:07
  • If those are x, y coordinates in your inner lists, consider using `Point` class instead, with an appropriate `Point.equals()` method. That would reduce the problem to non-nested lists. – tucuxi Jul 03 '14 at 12:11

1 Answers1

0

You should use the inner list as parameter to contains and disjoint?

Peter
  • 5,556
  • 3
  • 23
  • 38