About 14,700,000 results
Open links in new tab
  1. Java Returning method which returns arraylist? - Stack Overflow

    Jul 27, 2012 · public static List<Integer> myNumbers() { List<Integer> numbers = new ArrayList<Integer>(); numbers.add(5); numbers.add(11); numbers.add(3); return(numbers); } you can call it like so: List<Integer> stuff = Foo.myNumbers();

  2. java - How to return an arraylist? - Stack Overflow

    Jan 27, 2012 · To return an ArrayList, your method must include ArrayList in the declaration, like so: public ArrayList thisReturnsAnArrList(ArrayList list) { return list; //'list' is of the type 'ArrayList' } However, you can be more lenient and have a method return a List .

  3. How to Return an ArrayList in Java - Delft Stack

    Feb 2, 2024 · Specify the Return Type: Declare the return type of the function to be ArrayList<Type>, where Type represents the type of elements the ArrayList will hold. Return the ArrayList: Use the return keyword to send the populated ArrayList back to the calling code.

  4. java - How to create a method that returns an ArrayList - Stack Overflow

    Mar 26, 2013 · public ArrayList<String> getArrayList() { return myList; } public void addSomeStrings() { myList.add("Some String"); myList.add("Some Other String"); } and don't be afraid to walk through a Java tutorial.

  5. How to Return ArrayList in Java: A Complete Guide (2025)

    There are multiple ways to return ArrayList in Java, we will discuss one by one. 1. Basic Syntax for Returning an ArrayList. You can return an ArrayList from a simple method. For example, t he following method demonstrates how to return ArrayList in Java: public static ArrayList<String> getNames() { // Create an ArrayList.

  6. Return ArrayList in Java - Java2Blog

    Oct 10, 2023 · In different cases, you can return an ArrayList from a method in Java. These cases are as given below. Returning ArrayList from a static method. Returning ArrayList from a non-static method. The methods that you normally define under …

  7. How to Create a Java Method That Returns an ArrayList?

    In Java, you can define a method that returns an ArrayList by specifying the return type as ArrayList<T>, where T is the type of elements stored in the list. This allows for efficient management of dynamically sized collections of elements.

  8. Return an ArrayList in Java [2 ways] | Java Hungry

    Below are the steps to perform for returning an ArrayList from a static method: 1. Create a method that has ArrayList as the return type. 2. Create an ArrayList object. 3. Add the data to the ArrayList. 4. Last step is to return the ArrayList. ArrayList <String> arrlist = new ArrayList <String>(); . arrlist.add("First"); .

  9. Learn How To Return ArrayList In Java With Detailed Code …

    In this article, we will explore how to return an ArrayList in Java, covering the key concepts, syntax, and best practices. We'll also discuss common use cases and potential pitfalls to avoid when returning an ArrayList from a method.

  10. How to Pass an ArrayList to a Method in Java? - Tpoint Tech

    Sep 10, 2024 · After performing the necessary operations, you can use the return statement to pass the modified ArrayList back to the calling code. Replace "DataType" with the appropriate data type. In the calling code, you can assign the returned ArrayList to a new variable or overwrite the existing ArrayList.

  11. Some results have been removed
Refresh