How to create an empty list of strings in Java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // Create an empty list of strings
        List<String> stringList = new ArrayList<>();

        // Get the size of the list
        int size = stringList.size();

        // Print the size
        System.out.println("The size of the list is: " + size);
    }
}



/*
run:

The size of the list is: 0

*/

 



answered Jul 22, 2025 by avibootz
...