That is a very effective way to make your hash map execute with all the speed and athleticism of a dying snail. Write a hashCode method that computes a hash code for each instance; Carey has already shown you a possible implementation. If you are using an immutable type as the “K” in your map (as you should anyway), you may be able to cache the hash code.
vinayak shete wrote:. . . hashCode() method (will return same hash code - as 1 for each object.) . . .
Which fields do those classes have? Do any of the getXXX and getXXX methods have the same name in subclass and superclass.
Kathir jeyap wrote:. . . . abstract class many getters and setters and the class has few getters and setters . . . .
Sorry I didn&apost;t have the time to reply last night, but I think we agree on that point; once you have created a utility class to deal with the vagaries of Scanner, which as MW points out are badly documented in many places, you find keyboard input so much easier and more reliable. I think my KeyboardInputs class differs rather from your Inputter class, but I think we both find such classes much easier to use from the keyboard than a plain simple Scanner. The reason is that it is possible to ensure consistent format of the contents of a text file, so nextInt() actually finds an int, but you can't be sure there won't be errors when entering data live from the keyboard.
Knute Snortum wrote:Scanner is great for scanning text files, but I don't like it for getting input from the keyboard. . . . .