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

Related questions

1 answer 91 views
91 views asked Mar 18, 2023 by avibootz
1 answer 72 views
4 answers 207 views
1 answer 224 views
1 answer 91 views
2 answers 112 views
...