About 464,000 results
Open links in new tab
  1. java - Returning an empty array - Stack Overflow

    You can return empty array by following two ways: If you want to return array of int then. Using {}: int arr[] = {}; return arr; Using new int[0]: int arr[] = new int[0]; return arr; Same way you can return array for other datatypes as well.

  2. How to return an empty array in java? (with example) | Java2Blog

    Oct 11, 2023 · To return empty Array in Java, you can use curly braces. Using curly braces public static String[] returnEmptyStringArray() { String[] emptyArray = {}; return emptyArray; }

  3. java - How can I check whether an array is null / empty ... - Stack ...

    public boolean isEmpty( Object[] array ) throws Exception { if( array != null ) { if( array.length == 0 ) return true; } else { throw new Exception("isEmpty(): Array ref is null"); } return false; } The checking should be done in cascading way (not using && i.e. array != null && array.length == 0 ) since the order of evaluation of the ...

  4. How to Return Empty Array in Java - Delft Stack

    Feb 2, 2024 · To return an empty array using ArrayUtils, you can use the EMPTY_STRING_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_INT_ARRAY, EMPTY_LONG_ARRAY, etc., fields, depending on the type of array you need. In this example, we’ll focus on using ArrayUtils.EMPTY_STRING_ARRAY to return an empty array of …

  5. arraylist - Java return an empty list - Stack Overflow

    Apr 23, 2015 · Collections.emptyList() returns an immutable list, i.e., a list to which you cannot add elements if you want to perform any operation on your list, then create new instance of list and return it. query.setParameter("lang", lang); return query.getResultList(); } else { return new ArrayList<Lookup>(); // return array list instance.

  6. How to Return an Array in Java? - GeeksforGeeks

    Jun 29, 2022 · The java.lang.reflect.Array.getShort() is an in-built method of Array class in Java and is used to return the element present at a given index from the specified Array as a short. Syntax: Array.getShort(Object []array,int index) Parameters: array: The object array whose index is to be returned. inde

  7. Java - How to return empty array? - JavaProgramTo.com

    Nov 23, 2021 · In this tutorial, we'll learn how to return an empty array in java in different ways. An empty array means the array is not having any values and the length of the array is zero . Sometimes we need to return an empty array rather than returning null values.

  8. How to Return an Empty Array in Java: Differences Between Two ...

    Discover how to efficiently return an empty array in Java and understand the differences between using Collections.emptyList() and instantiating a new array.

  9. How to Check if an Array is Empty or Not in Java?

    Dec 9, 2024 · In Java, arrays do not have a built-in method like isEmpty() to check if they are empty. So, we need to use other ways to check if an array is empty in Java. Example: The simplest way to determine if an array is empty is by evaluating its length or verifying if it is null.

  10. Empty Array in Java - Tpoint Tech

    Sep 10, 2024 · In Java, an array has to satisfy one of the conditions that follows in order to be considered empty: It should be empty, meaning that the array's size should be zero. It should only contain empty items. The method of assigning values by declaring an array of a particular size without providing it any values is known as empty array initialization.

  11. Some results have been removed
Refresh