Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Created September 5, 2018 15:44
Show Gist options
  • Save juanbrusco/64b0647344675c5094509d0e9e88a3bf to your computer and use it in GitHub Desktop.
Save juanbrusco/64b0647344675c5094509d0e9e88a3bf to your computer and use it in GitHub Desktop.
Recursive function with ArrayList - Java
public static ArrayList<E> getFunction(Object x, int level, ArrayList<E> list) {
if (level == 1) {
Object x2 = DB.getInstance().getObjectById(x.getID());
list.add(x2);
return list;
} else {
Object x2 = DB.getInstance().getObjectById(x.getID());
level = level - 1;
list.add(x2);
return getFunction(x2, level, list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment