move https://www.baeldung.com/java-hashmap-inside-list code to core-java-collections-list-4 module (#12671)
This commit is contained in:
parent
dc1815c10c
commit
b836dce329
|
@ -12,5 +12,4 @@ This module contains articles about the Java List collection
|
|||
- [How to Count Duplicate Elements in Arraylist](https://www.baeldung.com/java-count-duplicate-elements-arraylist)
|
||||
- [Finding the Differences Between Two Lists in Java](https://www.baeldung.com/java-lists-difference)
|
||||
- [List vs. ArrayList in Java](https://www.baeldung.com/java-list-vs-arraylist)
|
||||
- [How to Store HashMap<String, ArrayList> Inside a List](https://www.baeldung.com/java-hashmap-inside-list)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-collections-list-2)
|
||||
|
|
|
@ -9,4 +9,5 @@ This module contains articles about the Java List collection
|
|||
- [Arrays.asList() vs Collections.singletonList()](https://www.baeldung.com/java-aslist-vs-singletonlist)
|
||||
- [Replace Element at a Specific Index in a Java ArrayList](https://www.baeldung.com/java-arraylist-replace-at-index)
|
||||
- [Difference Between Arrays.asList() and List.of()](https://www.baeldung.com/java-arrays-aslist-vs-list-of)
|
||||
- [How to Store HashMap<String, ArrayList> Inside a List](https://www.baeldung.com/java-hashmap-inside-list)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-collections-list-3)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.baeldung.list.listofhashmaps;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ListOfHashMapsUnitTest {
|
||||
|
||||
@Test
|
||||
void givenMaps_whenAddToList_thenListContainsMaps() {
|
||||
List<HashMap<String, List<String>>> booksAuthorsMapsList = new ArrayList<>();
|
||||
HashMap<String, List<String>> javaBooksAuthorsMap = new HashMap<>();
|
||||
HashMap<String, List<String>> phpBooksAuthorsMap = new HashMap<>();
|
||||
|
||||
javaBooksAuthorsMap.put("Head First Java", Arrays.asList("Kathy Sierra", "Bert Bates"));
|
||||
javaBooksAuthorsMap.put("Effective Java", Arrays.asList("Joshua Bloch"));
|
||||
javaBooksAuthorsMap.put("OCA Java SE 8", Arrays.asList("Kathy Sierra", "Bert Bates", "Elisabeth Robson"));
|
||||
phpBooksAuthorsMap.put("The Joy of PHP", Arrays.asList("Alan Forbes"));
|
||||
phpBooksAuthorsMap.put("Head First PHP & MySQL", Arrays.asList("Lynn Beighley", "Michael Morrison"));
|
||||
|
||||
booksAuthorsMapsList.add(javaBooksAuthorsMap);
|
||||
booksAuthorsMapsList.add(phpBooksAuthorsMap);
|
||||
|
||||
assertTrue(booksAuthorsMapsList.get(0)
|
||||
.keySet()
|
||||
.containsAll(new ArrayList<>(javaBooksAuthorsMap.keySet())));
|
||||
|
||||
assertTrue(booksAuthorsMapsList.get(1)
|
||||
.keySet()
|
||||
.containsAll(new ArrayList<>(phpBooksAuthorsMap.keySet())));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue