I wrote the java version:

public class Solution {
public static void main(String[] args) {
Solution sol = new Solution();
sol.getFactors(32);
}
public List<List<Integer>> getFactors(int n) {
List<List<Integer>> ans = new ArrayList<>();
List<Integer> li = new ArrayList<>();
factor(n, li, ans);
return ans;
}
private void factor(int n, List<Integer> list, List<List<Integer>> ans) {
int k = (list.isEmpty())? 2 : list.get(list.size() - 1);
while (k <= n / k) {
if (n % k == 0) {
list.add(k);
list.add(n/k);
ans.add(new ArrayList<>(list));
list.remove(list.size() - 1);
factor (n/k, list, ans);
list.remove(list.size() - 1);
}
k++;
}
}

}