Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to return to values for the given method in Java?

Hi,
I have the following code and I would like to return the following values from this method:

checkListMap and checkNameMap.

    public void getCheckedStandards(){
        TreeItem[] items = tree.getSelection();
        
        final Map<Integer, TreeItem> checkListMap;
        checkListMap = new HashMap<Integer, TreeItem>();
        
        final Map<Integer, String> checkNameMap;
        checkNameMap = new HashMap<Integer, String>();
        
        for (int i = 0; i < items.length; i++) {
            checkListMap.put(i, items[i]);
            //System.out.println("itemS: " + items[0]); 
            TreeItem[] child = items[i].getItems();
            for (int index=0; index < child.length; index++) { 
                if (child[index].getChecked()) {
                    //System.out.println("item: " + index + ": " + child[index].getText()); 
                    checkNameMap.put(index, child[index].getText());
                }
            }
        }  
        return  THESE TWO VALUES IN HERE
    }

Open in new window


Then I will call this method as below in another method:

   public void write2XML(String file){
       THE TWO RETURNED VALUES IN HERE = getCheckedStandards();
       
       createXMLData(checkListMap, checkNameMap, file);
       
   }

Open in new window


Can you please show me how I can do it?  Please note that the values that I want to return are hashmaps.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Point to be noted , you can't return two values in Java , but you can do it in Python
Avatar of Tolgar
Tolgar

ASKER

simple and perfect solution!!
Your welcome! :)