Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

linkedhashmap
values
dart
communitycreator

What is LinkedHashMap.values in Dart?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

LinkedHashMap is a hash-table based on MapMap contains a list of key-value pairs as an element.. The LinkedHashMap maintains the insertion order of the entries. We can read more about LinkedHashMap here.

The values property can be used to check "get all values of the LinkedHashMap" in the insertion order.

Syntax

Iterable<V> values

Return value

This property returns an iterable, which contains all the values of the LinkedHashMap.

The iterable contains the values in the insertion order.

Note: Modifying the map while iterating the values may result in an unhandled exception.This is a concurrent modification that takes place during an iteration.

Code

The code given below shows us how to get all the values of a map:

import 'dart:collection';
void main() {
//create a new LinkedHashMap which can have string type as key, and int type as value
LinkedHashMap map = new LinkedHashMap<String, int>();
// add two entries to the map
map["one"] = 1;
map["two"] = 2;
print('\nThe map is $map');
// use values property to get the values of the map
Iterable<int> values = map.values;
print('map.values: $values');
// using forEach and print the iterable
print('\nPrinting values Using forEach');
values.forEach((k) => print(k));
}
Using the values property to get all the values of the map

Explanation

  • Line 4: We create a new LinkedHashMap object with map.

  • Lines 7–8: We add two new entries to the map. Now, the map is {one: 1, two: 2}

  • Line 12: We use the values property to get all the values of the map. We will get the values as an Iterable object. We will get (1,2) upon printing the returned iterable.

  • Line 17: We use the forEach method of the values iterable and print all the elements (values) of the iterable.

RELATED TAGS

linkedhashmap
values
dart
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring