skip to Main Content

hi im trying to access a MultiValueMap which is in a Hashmap

this is my HashMap insideprojectDetails HashMap

private HashMap<String, ClassDetails> classDetailsMap = new HashMap<String, ClassDetails>();

inside that classDetailsMap i have MultiValueMap called methodDetailsMap

private MultiMap<String, MethodDetails> methodDetailsMap = new MultiValueMap<String, MethodDetails>();

when im trying to access the methodDetailsMap by

        Set<String> methodNamesSet = projectDetails.getClassDetailsMap().get(cls).getMethodDetailsMap().keySet();
    String[] methodNames = methodNamesSet.toArray(new String[0]);

    for (int i = 0; i < methodNames.length; i++) {
        String methodName = methodNames[i];
        System.out.println(cls + " "+methodName);
        //codes used to access key values
        Collection coll = (Collection) methodNamesSet.get(methodName);
        System.out.println(cls + " "+methodNamesSet.get(methodName));
    }

i get a error get saying cannot resolve method get(java.lang.String)

is there any way to access the MultiValueMap

2

Answers


  1. I read your code and as I understand first you need to get all method names of cls class then you want to get them one by one. So in the for loop you need to get from the getMethodDetailsMap().This will help you:

    for (int i = 0; i < methodNames.length; i++) {
                String methodName = methodNames[i];
                System.out.println(cls + " "+methodName);
                //codes used to access key values
                Collection coll = projectDetails.getClassDetailsMap().get(cls).getMethodDetailsMap().get(methodName);
                System.out.println(cls + " "+methodNamesSet.get(methodName));
            }
    
    Login or Signup to reply.
  2. Its a compilation error with your code. There is no get method in Set.

    methodNamesSet.get(methodName)

    To get method details, first loop through the set and then get method details from methodDetailsMap as below.

    MultiValueMap<String, MethodDetails>  methodDetailsMap = projectDetails.getClassDetailsMap().get(0).getMethodDetailsMap();
           Set<String> methodNamesSet = methodDetailsMap.keySet();
    
            for(String str: methodNamesSet) {
                    System.out.println(methodDetailsMap.get(str));
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search