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.
Then I will call this method as below in another method:
Can you please show me how I can do it? Please note that the values that I want to return are hashmaps.
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
}
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);
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Point to be noted , you can't return two values in Java , but you can do it in Python
ASKER
simple and perfect solution!!
Your welcome! :)