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.
TolgarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
I can see two basic options, the first would be to create a Class that's purpose is to hole the two maps. I could show you this if you like but first see if the next option is ok for you.

The other is to pass those HashMaps into the first method, ie. something like this...
   public void write2XML(String file){
       Map<Integer, TreeItem> checkListMap = new HashMap<Integer, TreeItem>();
       Map<Integer, TreeItem> checkNameMap= new HashMap<Integer, String>();

       getCheckedStandards(checkListMap, checkNameMap);
       
       createXMLData(checkListMap, checkNameMap, file);
       
   }

Open in new window

And then ...
    public void getCheckedStandards(final Map<Integer, TreeItem> checkListMap, final Map<Integer, String> checkNameMap){
        TreeItem[] items = tree.getSelection();
        
        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    *** No need to return anything ***
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sharon SethCommented:
Point to be noted , you can't return two values in Java , but you can do it in Python
0
TolgarAuthor Commented:
simple and perfect solution!!
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Your welcome! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.