How to create immutable list in Java

1 Answer

0 votes
import java.util.List;

public class MyClass
{
    public static void main(String[] args)
    {
        List<String> immutableList = List.of("Java", "C", "C++", "Rust", "Python");
 
        System.out.println(immutableList);
    }
}



/*
run:

[Java, C, C++, Rust, Python]

*/

 



answered Mar 18, 2023 by avibootz
...