Is it possible to return multiple values from a method? If possible, write how.
|
1 answer
Why not store values in an array or HashMap? Let's say
private HashMap<String, String> getValuesMap() { //ваш код HashMap<String, String> tmpHashMap = new HashMap<String, String>(); tmpHashMap.put("value1", "значение 1"); tmpHashMap.put("value2", "значение 2"); tmpHashMap.put("value3", "значение 3"); return tmpHashMap; } Well, where you call this method.
HashMap<String, String> values = getValuesMap(); String str = values.get("value1"); Maybe it was easier to do with the array String [], here you can choose
- fourWell, or you can just start a class, put return values in it, and return an instance of the class. - VladD
- Another option is to return an array of class Object , if you need to return several values of different types. - Roman Kotenko
|