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 :: flutter unable to find bundled java version 
Java :: R8: java.lang.OutOfMemoryError: GC overhead limit exceeded react-native 
Java :: java.lang.IllegalStateException: Could not obtain identifier 
Java :: android handler clear message queue 
Java :: java static variable 
Java :: jdbc dependency 
Java :: java array of array 
Java :: mongodb check if field exists java 
Java :: crit chance in java 
Java :: Implementing the ArrayList Class in java list 
Java :: System.out.println("j= 6"); 
Java :: how to call super onbackpressed in fragment 
Java :: how to set java path in windows 10 
Java :: android get user defined device name programmatically 
Java :: Number formatting java with locale 
Java :: JAVA Character Literals 
Java :: boolean 
Java :: Implementing the Vector Class in java list 
Java :: make quotation a string 
Java :: for loop condition java 
Java :: java set file folder permissions 
Java :: if not java 
Java :: check if input is empty java 
Java :: retrofit post body 
Java :: java program to search item from name in class 
Java :: put in spring rest api 
Java :: hashmap put method 
Java :: java continue statement 
Java :: java string strip 
Java :: java arraylist initialize with 0 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =