About 59,300 results
Open links in new tab
  1. How to call a method stored in a HashMap? (Java) [duplicate]

    Java 7 and below. What you really want to do is to create an interface, named for instance Command (or reuse for instance Runnable), and let your map be of the type Map<Character, Command>.

  2. What's the difference between map() and flatMap() methods in …

    Oct 31, 2014 · However, in Java, it's cumbersome for a method to return an arbitrary number of values, since methods can return only zero or one value. One could imagine an API where the mapper function for flatMap takes a value and returns an array or a List of values, which are then sent to the output.

  3. java - Iterate through a HashMap - Stack Overflow

    Jul 1, 2009 · There are several ways of iterating over a Map in Java. Let's go over the most common methods and review their advantages and disadvantages. Since all maps in Java implement the Map interface, the following techniques will work for any map implementation (HashMap, TreeMap, LinkedHashMap, Hashtable, etc.)

  4. Java: is there a map function? - Stack Overflow

    Feb 7, 2016 · Actually, no, there is often a definite performance hit with functional idioms, which is why they stress you should only use the facilities if you are certain it meets the two criteria outlined: net savings of LOC for the codebase as a whole, and proven performance gains due to lazy evaluation (or at least not performance hits).

  5. java - How to directly initialize a HashMap (in a literal way)? - Stack ...

    Map.copyOf. Java 10 added the method Map.copyOf. Pass an existing map, get back an immutable copy of that map. For efficiency, if the passed map is already truly immutable, the copyOf method returns a reference to the original without manufacturing a new map. About Collections.unmodifiableMap

  6. java - Time Complexity of HashMap methods - Stack Overflow

    By efficient I mean, a hash function might map two very different objects to the same bucket (this is called a collision) in case. There are various methods of solving collisions known as collision resolution technique such as. Using a better hashing function; Open addressing; Chaining e.t.c; Java uses chaining and rehashing to handle collisions.

  7. Most efficient way to increment a Map value in Java

    Sep 17, 2008 · Some test results. I've gotten a lot of good answers to this question--thanks folks--so I decided to run some tests and figure out which method is actually fastest.

  8. Mapping keys to methods in Java - Stack Overflow

    Nov 2, 2013 · I know how to use HashMaps and stuff to map keys to values. I was just wondering if you could map keys to methods as well. For example, a program asks the user for input. Then it calls a method that has its name as the input entered. ie: if the input is "cat", method cat() is invoked. Obviously one can use if statements, but is there an easier way?

  9. java - Understanding Map get method - Stack Overflow

    Nov 23, 2015 · While it is permissible for a map to contain itself as a value, extreme caution is advised: the equals and hashCode methods are no longer well defined on such a map. Therefor, even they note that you can change the mapped object, but certain things should be kept in mind if used as a key when changing fields that affect the equals return value.

  10. dictionary - Create Map in Java - Stack Overflow

    Feb 7, 2013 · I'd like to create a map that contains entries consisting of (int, Point2D) How can I do this in Java? I tried the following unsuccessfully. HashMap hm = new HashMap(); hm.put(1, new Point2D.Do...

Refresh