You should use Map<String, String> instead of a Hashtable and for each notation to iterate when possible.
Map<String, String> output = new HashMap<String, String>(); output.put("pos1","1"); output.put("pos2","2"); output.put("pos3","3"); for (String key : output.keySet()) { txt.append("\n" + key); }
Your current code does not work because Hashtable.keys() returns Enumeration , but you are trying to pass it to an ArrayList that cannot be assigned from Enumeration.
source share