map
The map() method creates a new array populated with the results of calling
a provided function on every element in the calling array.
const array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]
0
8
{"coord":{"lon":69.4167,"lat":34.5},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":294.37,"feels_like":293.07,"temp_min":294.37,"temp_max":294.37,"pressure":1008,"humidity":20,"sea_level":1008,"grnd_level":811},"visibility":10000,"wind":{"speed":1.72,"deg":278,"gust":1.88},"clouds":{"all":0},"dt":1624587596,"sys":{"type":1,"id":7381,"country":"AF","sunrise":1624579865,"sunset":1624631919},"timezone":16200,"id":1138957,"name":"Kabul","cod":200}
Thank you!
8
0
4.5
4
Map<String, String> words = new HashMap<>();
words.put("apple", "alma");
words.put("peer", "körte");
System.out.println(words.get("apple")); // alma
words.put("apple", "Apfel"); // Felülírja az értéket
System.out.println(words.get("apple")); // Apfel
Set<String> keys = words.keySet(); // Kulcsok
Collection<String> values = words.values(); // Értékek
for (Map.Entry<String, String> entry: words.entrySet()) {
System.out.println(entry.getKey() + " - " + entry.getValue());
}
Thank you!
4
0
3.75
4
om sharma
Thank you!
4
0
4.67
3
LIST: Can store duplicate values,
Keeps the insertion order.
It allows multiple null values,
Also we can read a certain value by index.
- ArrayList not syncronized, array based class
- LinkedList not synchronized, doubly linked
- Vector is synchronized, thread safe
SET: Can only store unique values,
And does not maintain order
- HashSet can have null, order is not guaranteed
- LinkedHashSet can have null and keeps the order
- TreeSet sorts the order and don't accept null
QUQUE : Accepts duplicates,
Doesn't have index num,
First in first our order.
MAP : is a (key-value format)
and keys are always unique,
and value can be duplicated.
- HashTable don't have null key, sychronized(thread-safe)
- LinkedHashMap can have null key, keeps order
- HasHMap can have null key, order is not guaranteed
- TreeMap doesn't have null key and keys are sorted
Thank you!
3
0
5
1
for (let {title, artist} of songs) {
return title
}
Thank you!
1
0
Are there any code examples left?
New code examples in category Other