Java – Count the number of items in a List

In Java, we can use List.size() to count the number of items in a List


package com.mkyong.example;

import java.util.Arrays;
import java.util.List;

public class JavaExample {

    public static void main(String[] args) {

        List<String> list = Arrays.asList("a", "b", "c");
        System.out.println(list.size());

    }

}

Output


3

References

  1. Java doc – List

No comments yet. Be the first to leave a comment!

Leave a Comment

Your email address will not be published. Required fields are marked *