OCP - 1
Classes, Desing Patterns, Principles, Generics and Collections
Classes, Desing Patterns, Principles, Generics and Collections
Set of flashcards Details
Flashcards | 124 |
---|---|
Language | English |
Category | Computer Science |
Level | Other |
Created / Updated | 31.01.2019 / 08.01.2020 |
Weblink |
https://card2brain.ch/box/20190131_ocp_1
|
Embed |
<iframe src="https://card2brain.ch/box/20190131_ocp_1/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
What is the signature of Map.merge?
V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
What does the Map.merge method do?
merge(key, value,function)
- If the the value for the given key is null or not present, insert the provided value.
- Otherwise, replace the value for the given key with the result of function
- function takes the value from the map as the first argument and the new value as the second one.
Map<String, String> leMap = new HashMap<String, String>();
String result;
result = leMap.merge("key", "v1", (k1, k2) -> k1 + k2);
result = leMap.merge("key", "v2", (k1, k2) -> k1 + k2);
result = leMap.merge("key", "v3", (k1, k2) -> k1 + k2);
System.out.println(result);
When defining an enum, where do the static method values() and valueOf() come from?
The compiler generates it on the enum class
When defining an enum, where do the methods name() and ordinal() come from?
All enums implicitly extend the enum in which these methods are defined