You cannot address a variable with its name as a string (except with reflection, but this is an overflow for this task).
You can add all of these ArrayList to another list. This is more flexible and therefore a better option.
List<List<ContactDetails>> lists2 = new ArrayList<List<String>>();
for (int i = 0; i < 10; i++) {
lists2.add(new ArrayList<ContactDetails>());
}
Or add them to the array and access them by array indices:
@SuppressWarnings("unchecked")
List<ContactDetails>[] lists = new List[10];
for (int i = 0; i < lists.length; i ++) {
lists[i] = new ArrayList<ContactDetails>();
}
Now:
for (int i = 1; i < 5; i++)
{
lists[i].clear();
lists2.get(i).clear();
}
Since both lists are Iterable and you can use foreach :
for (List list : lists)
{
list.clear();
}
for (List list : lists2) {
list.clear();
}
, Lambdas/Stream API, .