[Solved] How to get the smallest list?


I dont know how you named your Lists, so I’m just going to call them List a, b, c and d.

public List<?> getLongestList(List<?> a, List<?> b, List<?> c, List<?> d) {
  if (a.size() >= b.size() && a.size() >= c.size() && a.size() >= d.size()) return a;
  if (b.size() >= a.size() && b.size() >= c.size() && b.size() >= d.size()) return b;
  if (c.size() >= a.size() && c.size() >= b.size() && c.size() >= d.size()) return c;
  if (d.size() >= a.size() && d.size() >= b.size() && d.size() >= c.size()) return d;
  return null; //impossible to reach
}

I know this is a very ugly solution, but it’s easy to understand for java beginners, which I assume you are. If two or more Lists have the same size and are the longest, the first one of those will be returned.

solved How to get the smallest list?