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 192 views
192 views asked Mar 18, 2023 by avibootz
1 answer 175 views
175 views asked Dec 15, 2024 by avibootz
4 answers 399 views
1 answer 325 views
3 answers 287 views
1 answer 216 views
2 answers 233 views
...