0

Is there any way to return more than one value from a method in java?

for example in a get method, could you return more than one value?

30th Nov 2016, 1:06 AM
Ahmed Zaky
Ahmed Zaky - avatar
3 Respostas
+ 3
No, we can't return more than one value. If you would like to do so, then try storing in and returning an object or an array or a List etc, from which you can retrieve those values.
30th Nov 2016, 1:12 AM
Sai Kishore
Sai Kishore - avatar
+ 2
Yes you can return any type of object, it could be a collection object, or an object than you create from your method, of course you have to declare that return type in than method public ArrayList<SomeClass> method() { ArrayList<SomeClass> variable ... ... return variable } Or public studentsClass method() { studentsClass variable ... ... return variable }
30th Nov 2016, 1:31 AM
Dago VF
Dago VF - avatar
+ 1
so if I store those multiple values in an array, can I return the whole of the array and not just an index or one element in the array? @Sai
30th Nov 2016, 1:17 AM
Ahmed Zaky
Ahmed Zaky - avatar