
How to return 2 values from a Java method? - Stack Overflow
May 14, 2010 · I am trying to return 2 values from a Java method but I get these errors. Here is my code: // Method code public static int something(){ int number1 = 1; int number2 = 2; return …
java - How to return multiple values? - Stack Overflow
If you are returning more than 1 value that are related, then it makes sense to encapsulate them into a class and then return an object of that class. If you want to return unrelated values, then …
java - return two variables from one method - Stack Overflow
Oct 27, 2014 · You cannot return two different values in methods in Java. When this need occurs, you usually have two options: Create a class which has the types you want to return, and then …
function - Return multiple values in Java - Stack Overflow
Nov 15, 2012 · In Java, when you want a function to return multiple values, you must. embed those values in an object you return; or change an object that is passed to your function; In …
java - How to return two strings in one return statement ... - Stack ...
May 13, 2015 · return new String[]{ans1,ans2}; This should work. To your other question in the comments. Since Java is strongly typed language, all the variables/results should be …
oop - Return two values from a java method - Stack Overflow
Jul 4, 2012 · The most OOP it will be create a class to encapsulate those 2 properties, something like that. private class UserInfo { private Address address; private Team team; } Or if you want …
Is it possible to return more than one value from a method in Java?
Mar 8, 2013 · Return a Map containing the values. The problem with this (and the next) approach is that you are straying into an area that requires runtime type checking ... and that can lead to …
How to return multiple values from a method in Java
Apr 30, 2019 · and make return type of your method to the above class. 2- Return Map with key value pairs 3- Make Interface and call Abstract method from where you want to return the …
How to return multiple objects from a Java method?
Jan 19, 2009 · n-length - can handle any number of return values; no-cast - no need to cast from Object; type-safe - the types are checked via Java's generics; Cons: inefficient for large …
java - Getting a function to return two integers - Stack Overflow
Sep 6, 2010 · As per question, he wants to return two numbers, which is possible by using Array as a return type. Your solution is returning the sum of two numbers. Appreciating efforts.