About 198,000 results
Open links in new tab
  1. When to use a Map instead of a List in Java? - Stack Overflow

    Java map: An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. Java list: An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted.

  2. List vs. Map: Which takes less space and more efficient?

    May 4, 2014 · You can use a Map as a List by mapping Integers to your elements, but that's overcomplicating things a bit. However, even within List and Map you can have different implementations that differ wildly in asymptotic performance. With few exceptions, data structures will take O(n) space, which makes sense.

  3. Java Stream API - Best way to transform a list: map or forEach?

    The second way is preferred from functional programming point of view since the map function can accept stateless lambda functions. More explicitly, the lambda passed to the map function should be. Non-interfering, meaning that the function should not alter the source of the stream if it is non-concurrent (e.g. ArrayList).

  4. java - What is the difference between Lists ... - Stack Overflow

    In this Java article we will see difference between Map, Set and List in Java and learn when to use List, Set or Map. Set vs List vs Map in Java. As I said Set, List and Map are interfaces, which defines core contract e.g. a Set contract says that it can not contain duplicates.

  5. Performance benefits of using a List vs Map in Java

    Oct 4, 2017 · obviously if my aim is to just work on values I would also use List. yes, that's correct . But do we get any performance boost. Please note,. the Map is not a simple structure. For each item in a map, an "Entry" object is created with references to the key and the value object, an hash array is created, etc.. so using map you definitely use ...

  6. java - List<Map<String, String>> vs List<? extends Map ... - Stack …

    Mar 22, 2012 · Today, I have used this feature, so here's my very fresh real-life example. (I have changed class and method names to generic ones so they won't distract from the actual point.)

  7. java - List vs Map/Dictionary - Stack Overflow

    Mar 15, 2011 · There are cases where you use a List, be it array or linked. There are other situations where you use a Map, in java, or Dictionary or something else similar. Why would you ever use a List when a Map gives exactly the same functionality, that is access by an index (in this case integer...). Shouldn't the Map always be prefered to the list?

  8. java - How list differ from map? - Stack Overflow

    May 3, 2012 · Map Interface A Map cares about unique identifiers. You map a unique key (the ID) to a specific value, where both the key and the value are, of course, objects. The Map implementations let you do things like search for a value based on the key, ask for a collection of just the values, or ask for a collection of just the keys.

  9. What is the difference between the HashMap and Map objects in …

    Jan 5, 2017 · Exactly--and you always want to use the most general interface you possibly can. Consider ArrayList vs LinkedList. Huge difference in how you use them, but if you use "List" you can switch between them readily. In fact, you can replace the right-hand side of the initializer with a more dynamic statement. how about something like this:

  10. Java - map a list of objects to a list with values of their property ...

    List<ViewValue> source = newArrayList(new ViewValue(1), new ViewValue(2), new ViewValue(2)); We could make transformation with List class from Javaslang library (on the long run the collect is not convenient): List<Long> result = io.vavr.collection.List.ofAll(source).map(ViewValue::getId).toJavaList();

Refresh