For example,I input 3 Strings:Hagzou Hugzou Jigxng as the keys of a HashMap,
but when I traversing the HashMap by key,the order has been changed:Hugzou Hagzou Jigxng.
Is that possible to make sure the order can not be changed when output the keys?
like this:
input: Hagzou Hugzou Jigxng ###
output: Hagzou Hugzou Jigxng
thx a lot!
Here is my code:
    HashMap< String, Integer > distance = new HashMap< String, Integer >(); 
    Scanner input = new Scanner(System.in);     
    while (true) {
        String city = input.next();
        if (city.equals("###"))
            break;
        distance.put(city, null);
    }
    for (String city : distance.keySet()) {
        System.out.println(city);
    }
 
    