OCP - 1

Classes, Desing Patterns, Principles, Generics and Collections

Classes, Desing Patterns, Principles, Generics and Collections


R. ..
This flashcard set delves into advanced Java programming concepts, focusing on collections, methods, and object-oriented principles. It covers topics like enums, generic types, and various collection classes such as ArrayList, Map, and Set. The flashcards explore method signatures, static and instance methods, and the use of interfaces. Programmers looking to master Java's advanced features and best practices will find this set particularly useful for understanding and applying these concepts in their code.
Flashcards
124
Students
2
Language
English
Category
Computer Science
Level
Other
Created / Updated
31.01.2019 / 08.01.2020

Flashcards

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