In Java 8 and above you can create a List of Functional Interfaces to store the methods, as the following example shows:

// Create a list of Consumer
List<Consumer<String>> methodList= new ArrayList<>();

// Store the methods in the list
methodList.add(p -> method1(p));
methodList.add(p -> method2(p));
methodList.add(p -> method3(p));
methodList.forEach(f -> f.accept("Hello"));

Functions with no arguments you can use Runnable:

List<Runnable> methods = new ArrayList<>();
methods.add(() -> method1());
methods.add(() -> method2());
methods.add(() -> method3());
methods.forEach(f -> f.run());
Answer from Rodrigo Eggea on Stack Overflow
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ util โ€บ List.html
List (Java Platform SE 8 )
3 weeks ago - The List interface provides four methods for positional (indexed) access to list elements. Lists (like Java arrays) are zero based. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example).
๐ŸŒ
W3Schools
w3schools.com โ€บ JAVA โ€บ java_list.asp
Java List
Java Examples Java Videos Java ... ... The List interface is part of the Java Collections Framework and represents an ordered collection of elements....
Discussions

collections - How to create list filled with methods in Java and iterate over it (using methods) - Stack Overflow
In Java 8 and above you can create a List of Functional Interfaces to store the methods, as the following example shows: More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I create a List of functions in Java? - Stack Overflow
I intend to stream the functions and pass them the same data. ... Yes, naturally. ... The problem is that there's not enough type information to infer the parameterization of List, so it defaults to List. Either replace var with the actual type (e.g., List>) or use ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to create a Java Function list? - Stack Overflow
I want to create a list from Java Functions. But When I try to add a function to functions list, it says; Non-static variable cannot be referenced from a static context I don't get which method is More on stackoverflow.com
๐ŸŒ stackoverflow.com
Multiple ways to declare a list(JAVA)?
The use of List without the generic argument, is called a raw-type. You shouldn't use those. The generics are used to tell the compiler what type it should accept/return from this list... List badList = new ArrayList(); badList.add(1); badList.add("Boom"); badList.add(badList); The preferred forms are: List numbers = new ArrayList<>(); Or maybe: var numberList = new ArrayList(); Note: If you know how many items you'll be adding you can also supply a capacity for the ArrayList. More on reddit.com
๐ŸŒ r/learnprogramming
7
2
January 18, 2023
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ list-interface-java-examples
List Interface in Java - GeeksforGeeks
Since List is indexed, the element is replaced at the specified position. ... import java.util.*; class Geeks { public static void main(String args[]) { // Creating an object of List interface List<String> al = new ArrayList<>(); // Adding elements to object of List class al.add("Geeks"); al.add("Geeks"); al.add(1, "Geeks"); System.out.println("Initial ArrayList " + al); // Setting (updating) element at 1st index using set() method al.set(1, "For"); System.out.println("Updated ArrayList " + al); } }
Published ย  February 3, 2026
๐ŸŒ
IONOS
ionos.com โ€บ digital guide โ€บ websites โ€บ web development โ€บ java list
What is a Java list? - IONOS
November 3, 2023 - Lists are one of the funยญdaยญmenยญtal data strucยญtures in Java proยญgramยญming and can be used in a variety of ways. They contain elements, which are arranged in an ordered sequence. You can add, modify, delete or query elements in a list.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-list
Java List Interface: Complete Guide with Examples | DigitalOcean
August 3, 2022 - Master Java List interface with ArrayList, LinkedList, and Vector. Complete tutorial covering operations, iteration, sorting, and best practices with examples.
๐ŸŒ
Oracle
docs.oracle.com โ€บ en โ€บ java โ€บ javase โ€บ 21 โ€บ docs โ€บ api โ€บ java.base โ€บ java โ€บ util โ€บ List.html
List (Java SE 21 & JDK 21)
January 20, 2026 - The List interface provides four methods for positional (indexed) access to list elements. Lists (like Java arrays) are zero based. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example).
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-list-of-method-explained-e21e66f97e82
Java's List.of() Method Explained | Medium
December 4, 2024 - Learn how Java's List.of() method creates immutable lists, its advantages for constant data, and how it compares with mutable lists using practical examples.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 6 โ€บ docs โ€บ api โ€บ java โ€บ util โ€บ List.html
List (Java Platform SE 6)
The List interface provides four methods for positional (indexed) access to list elements. Lists (like Java arrays) are zero based. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example).
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_ref_arraylist.asp
Java ArrayList Reference
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... A list of all ArrayList methods can be found in the table below.
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ java โ€บ java list methods โ€“ sort list, contains, list add, list remove
Java List Methods - Sort List, Contains, List Add, List Remove
April 1, 2025 - This Tutorial Explains Various Java List Methods such as Sort List, List Contains, List Add, List Remove, List Size, AddAll, RemoveAll, Reverse List & More:
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ library
Java Library Functions | Programiz
This page contains all methods in Python Standard Library: built-in, dictionary, list, set, string and tuple.
๐ŸŒ
Amigoscode
blog.amigoscode.com โ€บ p โ€บ 18-most-used-java-list-methods
18 Most Used Java List Methods
December 14, 2023 - 3. remove(Object o) - Removes the first occurrence of the specified element from the list.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ multiple ways to declare a list(java)?
r/learnprogramming on Reddit: Multiple ways to declare a list(JAVA)?
January 18, 2023 -

These all work, but I'm confused as to why they're different:

        List temp1 = new ArrayList<Integer>();
        List temp2 = new ArrayList<>(); 
        List<Integer> temp3 = new ArrayList<>();
        List<Integer> temp4 = new ArrayList<Integer>();

        temp1.add(1);
        temp1.add(2);

        temp2.add(3);
        temp2.add(4);

        temp3.add(5);
        temp3.add(6);

        temp4.add(7);
        temp4.add(8);

        System.out.println(temp1); //[1, 2]
        System.out.println(temp2); //[3, 4]
        System.out.println(temp3); //[5, 6]
        System.out.println(temp4); //[7, 8]

I was always under the impression that temp4 was the required way, but these all run and work. When should I use each or is it bad practice to not use temp 4?

๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-lists-work-in-java
Java List โ€“ Example Lists in Java
January 31, 2023 - You can use the Java List interface to store objects/elements in an ordered collection. It extends the Collection interface. The List interface provides us with various methods for inserting, accessing, and deleting elements in a collection. In t...
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ java-list-methods
Java List Methods Explained: From Basics to Advanced
February 27, 2024 - In this example, we create a new ArrayList and add the string โ€˜Helloโ€™ to it using the add() method. We then retrieve the first item in the list using the get() method, which returns โ€˜Helloโ€™. This is just a basic introduction to Java List methods, but thereโ€™s much more to learn about these versatile tools.
Top answer
1 of 2
4

In Java, this is the best you can hope for. For each new function, you must make an additional change to ensure that it gets called. While you could pass an array of Functions to prevent setting up each individual call, you still need to alter the array with each successive function created, so it is ultimately no better.

Though if you're like me, you may want to categorize these functions so that you can have a single comprehensive list. While it doesn't reduce the amount of changes you'll need to make to the code, this way I find is more organized.

public enum TestFunctions {
    BUBBLE_SORT(SortingAlgorithms::bubbleSort),
    QUICK_SORT(SortingAlgorithms::quickSort),
    MERGE_SORT(SortingAlgorithms::mergeSort),
    INSERTION_SORT(SortingAlgorithms::insertionSort);

    UnaryOperator<Integer[]> function;

    private TestFunctions(UnaryOperator<Integer[]> function) {
        this.function = function;
    }

    public Integer[] call(Integer[] input) {
        return this.function.apply(input);
    }
}

Like this, your code can separate the function from where it's implemented. You'd still need to add the new function here, but there's no getting around this unless you used reflection. Though you could use reflection, I would strongly discourage you from doing so. My experience is that it tends to create more problems than it solves in the long run.

Good luck!

2 of 2
2

If you want to create a list of functions, that is very easy. You literally just need to create a List of Functions. Example:

import java.util.List;
import java.util.function.Function;

class Test {
  private static List<Function<int[], int[]>> functions = List.of(
      a -> new int[] { a[0] + a[1] },
      a -> new int[] { a[0] - a[1] }
  );

  public static void main(String[] args) {
    for (var f : functions) {
      System.out.println(f.apply(new int[] { 1, 2 })[0]);
    }
  }
}

// 3
// -1