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?
3 Réponses
+ 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.
+ 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
}
+ 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