answersLogoWhite

0

You can do this by returning it just like any other data type.

int[] f() {

return new int[0];

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Can the return type of a method be an array?

Depends on the language. For Java, yes.


How many values can a method return in Java?

A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.


What is the return type of finally method in java?

The final and finally keywords have no impact on the return type of a method in Java.


Write a function in java that accepts an array of integers and returns the second largest integer in the array Return -1 if there is no second largest?

Method 1: Sort the array in descending order, compare 1st and 2nd if not same , return 2nd if same return -1 Method 2: Find the largest number in the array, initialize another array with dimension 1 less than of original. Copy the array elements from the original array minus the largest element. not select largest from the second array and compare with the previous one if not same return the second largest if same return -1


Is array list a value type or reference type?

Array lists are objects and are of the reference data types. If you pass an array list from a java method to another as an argument, you need not return this from the target method because the modifications to the list would be happening in its value and hence would be available in the parent or calling method without being received as an output from the called method.


What does a void method do?

In Java, this keyword is used to specify that the method has no return value.


What are benefits of array in java?

array example in java


Why should the java main method has the return type as void?

A void method is one that returns no value. The Java main() method is the first method to be called, therefore it doesn't need to return a value to another Java method, therefore it is declared as void. If something needs to be returned to the operating system, this is done differently, not by "returning a value" in the sense of Java.


What is default return type for method in java?

default return type is : true


How do you determine the size of an array of int passed to a method?

It really depends on the language. In Java, you can use the .length property.


What is the return keyword in Java?

this is the type of the value that the method returns to its caller


Can return statement be in a void method in java?

the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.