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 110 views
110 views asked Mar 18, 2023 by avibootz
1 answer 72 views
4 answers 207 views
1 answer 224 views
3 answers 118 views
1 answer 104 views
2 answers 110 views
...