ListOfListService class
unknown
java
5 years ago
1.6 kB
17
Indexable
import java.util.ArrayList;
public class ListOfListService {
public static boolean contains(ArrayList<ArrayList<Integer>> list, Integer target) {
if (list == null) {
return false;
}
// iterate through every sublist of list
for (int i = 0; i < list.size(); i++) {
// checking wheter sublist contain a target or not if yes return true
if (list.get(i).contains(target))
return true;
}
return false;
}
public static Integer getItem(ArrayList<ArrayList<Integer>> list, int i, int k) {
if (list == null) {
return null;
}
if (i >= 0 && i < list.size() && k < list.get(i).size()) {
return list.get(i).get(k);
}
return null;
}
public static boolean isSubListNotNull(ArrayList<ArrayList<Integer>> list, int i) {
if (list == null) {
return false;
}
// checking boundary
if (i >= 0 && i < list.size()) {
// taking sublist from list and testing its size
ArrayList<Integer> arrayList = list.get(i);
if (arrayList != null) {
return true;
}
}
return false;
}
public static Integer getFirstItem(ArrayList<ArrayList<Integer>> list) {
if (list == null)
return null;
// checking boundary
if (list.size() == 0 || list.get(0).size() == 0) {
return null;
}
// returning first element
return list.get(0).get(0);
}
}
Editor is loading...