DevTech101

DevTech101
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

Default java library

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Google java library

import java.util.Set;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

Apache java library

package com.sqlitedb.examples.util.map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Full working example

/**
 *
 * @author Eli Kleinman
 */
public class TestArr {

    public void TestArr() {
        // create map to store
        Map<string, list<string="">> map = new HashMap<>();

        List valSetOne = new ArrayList<>();
        valSetOne.add("Apple");
        valSetOne.add("Aeroplane");

        List valSetTwo = new ArrayList<>();
        valSetTwo.add("Bat");
        valSetTwo.add("Banana");
        valSetTwo.add("Apple");

        List valSetThree = new ArrayList<>();
        valSetThree.add("Joe");
        valSetThree.add("Jany");

        map.put("A", valSetOne);
        map.put("B", valSetTwo);
        map.put("G", valSetThree);

        // iterate and display values
        System.out.println("Fetching Keys and corresponding [Multiple] Values n");
        //for (Map.Entry<string, list<string="">> entry : map.entrySet()) {
        map.entrySet().forEach((entry) -> {
            String key = entry.getKey();
            List values = entry.getValue();
            //System.out.println("Key = " + key);
            //System.out.println("All Values = " + values.size());
            //System.out.println("Value zero = " + values.get(1));
            //for (i values.size()) {
            for(int x = 0; x < values.size(); x = x + 1) {
                System.out.println("Key: " + key + " " + "Cur Item: " + values.get(x));
            }
        });
    }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: