How to create immutable set in Java

1 Answer

0 votes
import java.util.Set;
 
public class MyClass
{
    public static void main(String[] args)
    {
        Set<String> immutableSet = Set.of("Java", "C", "C++", "Rust", "Python");
 
        System.out.println(immutableSet);
    }
}



/*
run:

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

*/

 



answered Mar 18, 2023 by avibootz

Related questions

1 answer 126 views
126 views asked Mar 18, 2023 by avibootz
1 answer 88 views
4 answers 224 views
1 answer 243 views
3 answers 145 views
1 answer 128 views
2 answers 129 views
...