About 294,000 results
Open links in new tab
  1. How to return 2 values from a Java method? - Stack Overflow

    May 14, 2010 · Instead of returning an array that contains the two values or using a generic Pair class, consider creating a class that represents the result that you want to return, and return …

  2. How to return multiple objects from a Java method?

    Jan 19, 2009 · I want to return two objects from a Java method and was wondering what could be a good way of doing so? The possible ways I can think of are: return a HashMap (since the …

  3. 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 …

  4. 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 …

  5. 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 …

  6. oop - Return two values from a java method - Stack Overflow

    Jul 4, 2012 · Let's say I have a method in java, which looks up a user in a database and returns their address and the team they are on. I want to return both values from the method, and …

  7. 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 …

  8. Return two arrays in a method in Java - Stack Overflow

    Jun 14, 2011 · class User { String name; int[] values; // setters and getters for name, values } User[] doSomething() { User[] users = new User[10]; // fill the array return users; } Create a …

  9. function - Return multiple values in Java - Stack Overflow

    Feb 13, 2014 · 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 …

  10. Is it possible to return more than one value from a method in Java?

    Mar 8, 2013 · No it is not. Java allows only one value to be returned. This restriction is hard-wired into the language. However, there are a few approaches to deal with this restriction: Write a …

Refresh