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

    May 14, 2010 · You can only return one value in Java, so the neatest way is like this: return new Pair<Integer>(number1, number2); Here's an updated version of your code:

  2. Returning Multiple values in Java - GeeksforGeeks

    Sep 13, 2018 · Java doesn't support multi-value returns. We can use following solutions to return multiple values. We can return an array in Java. Below is a Java program to demonstrate the …

  3. How to Return Multiple Values From a Java Method - Baeldung

    May 11, 2024 · In this tutorial, we’ll learn different ways to return multiple values from a Java method. First, we’ll return arrays and collections. Then we’ll demonstrate how to use container …

  4. Return Multiple Values in Java [5 Different Methods]

    Feb 22, 2022 · We can use any of the five shown approaches as per the program requirement to return multiple values in Java. Return an array of specific type or object, Return using the Pair …

  5. How to Return Multiple Values in Java - Delft Stack

    Feb 2, 2024 · In this tutorial, we will learn to return multiple values in Java. We cannot return more than one value from a method directly in Java, but we can use other features of Java, like …

  6. Return multiple values from a method in Java | Techie Delight

    Oct 25, 2023 · This post will discuss how to return multiple values from a method in Java using a POJO class, an array, collection, delimiter & javafx.util.Pair class

  7. Java Method Return Multiple Values - A Comprehensive Guide

    This tutorial will explore how to return multiple values in Java using various techniques, including arrays, collections, and custom objects. Understanding how to return multiple values can …

  8. Java how to return two variables? - Stack Overflow

    Feb 6, 2014 · Java has no native way of doing this, you only can return one Object or primitive. This leaves you two options: Return an array with length 2. public int[] reduce() { ... return new …

  9. How to return 2 values from a Java method? - W3docs

    There are a few ways you can return multiple values from a Java method: Return an array: You can create an array that contains the values you want to return, and then return the array. For …

  10. java - A way to return multiple return values from a method: put …

    Short answer: You can return an array or a List with the two values. I personally would write two distinct methods, like int x = obj.getX(); int y = obj.getY();

Refresh