Metoda Java HashMap replaceAll () nadomesti vsa preslikave hashmapa z rezultatom iz navedene funkcije.
Sintaksa replaceAll()metode je:
 hashmap.replaceAll(Bifunction function)
Tu je hashmap predmet HashMaprazreda.
replaceAll () Parametri
replaceAll()Postopek traja samo en parameter.
- funkcija - operacije, ki se uporabijo pri vsakem vnosu hashmapa
replaceAll () Vrnjena vrednost
replaceAll()Metoda ne vrne nobene vrednosti. Namesto tega vse vrednosti hashmapa nadomesti z novimi vrednostmi iz funkcije.
Primer 1: spremenite vse vrednosti v velike črke
 import java.util.HashMap; class Main ( public static void main(String() args) ( // create an HashMap HashMap languages = new HashMap(); // add entries to the HashMap languages.put(1, "java"); languages.put(2, "javascript"); languages.put(3, "python"); System.out.println("HashMap: " + languages); // Change all value to uppercase languages.replaceAll((key, value) -> value.toUpperCase()); System.out.println("Updated HashMap: " + languages); ) )
Izhod
HashMap: (1 = java, 2 = javascript, 3 = python) Posodobljen HashMap: (1 = JAVA, 2 = JAVASCRIPT, 3 = PYTHON)
V zgornjem primeru smo ustvarili hashmap z imenom jeziki. Opazite vrstico,
 languages.replaceAll((key, value) -> value.toUpperCase());
Tukaj,
- (key, value) -> value.toUpperCase()je lambda izraz. Vse vrednosti hashmapa pretvori v velike črke in jih vrne. Če želite izvedeti več, obiščite Java Lambda Expression.
- replaceAll()zamenja vse vrednosti hashmapa z vrednostmi, ki jih vrne lambda izraz.
2. primer: Vse vrednosti zamenjajte s kvadratom tipk
 import java.util.HashMap; class Main ( public static void main(String() args) ( // create an HashMap HashMap numbers = new HashMap(); // insert entries to the HashMap numbers.put(5, 0); numbers.put(8, 1); numbers.put(9, 2); System.out.println("HashMap: " + numbers); // replace all value with the square of key numbers.replaceAll((key, value) -> key * key);; System.out.println("Updated HashMap: " + numbers); ) )
Izhod
HashMap: (5 = 0, 8 = 1, 9 = 2) Posodobljen HashMap: (5 = 25, 8 = 64, 9 = 81)
V zgornjem primeru smo ustvarili hashmap z imenom številke. Opazite vrstico,
 numbers.replaceAll((key, value) -> key * key);
Tukaj,
- (key, value) -> key * key- izračuna kvadrat ključa in ga vrne
- replaceAll()- zamenja vse vrednosti hashmapa z vrednostmi, ki jih vrne- (key, value) -> key * key








