I want to retreive at the finaly of call recursive method, a set of integer with result : {10,20,30} but in this program i have porblem ,
public static void main(String[] args) { HashMap<Integer, Set<Integer>> myMap = new HashMap(); myMap.put(1, new HashSet(){{add(10);}}); myMap.put(2, new HashSet(){{add(20);}});myMap.get(2).add(30); myMap.put(3, new HashSet()); HashSet<Integer> setInteg = new HashSet(); recursivFonc(setInteg, myMap, 1); System.out.println(setInteg); } static HashSet recursivFonc(HashSet<Integer> setInteg, HashMap<Integer, Set<Integer>> map, int cont) { System.out.println(cont); if(map.get(cont) != null) { Set<Integer> set = map.get(cont); for(Integer intg : set) { setInteg.add(intg); return recursivFonc(setInteg, map, cont); } } return setInteg; } how did I do to get to the end a set with {10,20,30} ?