say i have a Map, a HashMap, and its key is a bunch of Integer and the values is a List of strings. i.e.

{1=["A", "B", "C", "D"], 2=["A", "B", "E", "D"], 3=["D", "F", "G"]}

then i have a Set that stores a list and it looks like this:

[["A", "B", "C", "D", "F", "G" ], ["A", "B", "E", "D", "F", "G"]]

from the above set we can see that in the first list is ["A", "B", "C", "D", "F", "G"]

and this list belongs matchest the value in the map with the key 1 and 3.

for the second list in the set ["A", "B", "E", "D", "F", "G"], this list matchest the value in the map with the key 2 and 3

thanks

ps: i've also built a rough code just to set the map and the setOfList (i.e. a HashSet that stores a bunch of List object)

but having trouble creating it, at the moment the Set only wants to keep one of the list i.e. the last list added to the Set:
here is my code

import java.util.*;
 
public class TestMap {
    
    private Map keyMap = new HashMap();
    private List listA = new ArrayList();
    private List listB = new ArrayList();
    private List listC = new ArrayList();
 
    
    private Set searchKey = new HashSet();
    
    public TestMap(){
        // setting up the map
        String[] a = {"A", "B", "C", "D" };
        String[] b = {"A", "B", "E", "D" };
        String[] c = {"D", "F", "G"};      
        for (int i = 0; i < a.length; i++){ listA.add(a[i]); }
        for (int i = 0; i < b.length; i++){ listB.add(b[i]); }
        for (int i = 0; i < c.length; i++){ listC.add(c[i]); }
        
        keyMap.put(Integer.valueOf(1), listA);
        keyMap.put(Integer.valueOf(2), listB);
        keyMap.put(Integer.valueOf(3), listC);
        
        // setting up the set of list
        List forSetA = new ArrayList();
        List forSetB = new ArrayList();
        String[] d = {"A", "B", "C", "D", "F", "G" };
        for (int i = 0; i < d.length; i++){ forSetA.add(d[i]); }
        String[] e = {"A", "B", "C", "D", "F", "G" };
        for (int i = 0; i < e.length; i++){ forSetB.add(e[i]); }
 
        searchKey.add(createTemp(forSetA));
        searchKey.add(createTemp(forSetB));      
        System.out.println(keyMap);
        System.out.println(searchKey);
       }
    
    
    public static void main(String[] args) {
        new TestMap();
    }
  
    private List createTemp(List l) {
        List temp = new ArrayList();
        Iterator it = l.iterator();
        while (it.hasNext()) {
            temp.add(it.next());
        }
        return temp;
    }
   
}

Recommended Answers

All 2 Replies

ok solved the first problem... adding

forSetA and forSetB has the same thing it was a typo mistake...

but i still have a bigger problem to solve (see... orriginal thread..)

Member Avatar for iamthwee

Idea!

Effectively all you are doing is looking for substrings within a string?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.