Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

return two values in java

// A Java program to demonstrate that a method
// can return multiple values of same type by
// returning an array
class Test {
    // Returns an array such that first element
    // of array is a+b, and second element is a-b
    static int[] getSumAndSub(int a, int b)
    {
        int[] ans = new int[2];
        ans[0] = a + b;
        ans[1] = a - b;
  
        // returning array of elements
        return ans;
    }
  
    // Driver method
    public static void main(String[] args)
    {
        int[] ans = getSumAndSub(100, 50);
        System.out.println("Sum = " + ans[0]);
        System.out.println("Sub = " + ans[1]);
    }
}
Comment

multiple return values in function java

Tuple2<Coordinates, Double> getMostDistantPoint(List<Coordinates> coordinatesList, 
                                                       Coordinates target) {

    return coordinatesList.stream()
      .map(coor -> new Tuple2<>(coor, coor.calculateDistance(target)))
      .max((d1, d2) -> Double.compare(d1.getSecond(), d2.getSecond())) // compare distances
      .get();
}
Comment

PREVIOUS NEXT
Code Example
Java :: check if string is decimal java 
Java :: java check if instance of subclass 
Java :: java constructor 
Java :: java abstract method 
Java :: how to call a void method from another class in java 
Java :: java or cpp 
Java :: java final class 
Java :: java compare char 
Java :: resultset methods in jdbc 
Java :: can you use java in unity 
Java :: imperative programming paradigm example 
Java :: configuration spring boot dependency for freemarker configuration 
Java :: java font bold italic 
Java :: java gerüst 
Java :: graph with dependies problem 
Java :: jbutton 
Sql :: reset ids in mysql 
Sql :: sql server 2016 reseed identity 
Sql :: how to truncate table with foreign key constraint 
Sql :: mysql find tables with name 
Sql :: set max_allowed_packet mysql 
Sql :: oracle enable job 
Sql :: postgresql calculate age from birthdate 
Sql :: oracle table size 
Sql :: find mysql version linux 
Sql :: Mysql query add column with default string value 
Sql :: mysql version check cmd 
Sql :: tsql get beginning of year 
Sql :: restart mysql server ubuntu 
Sql :: sqlite connection string 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =