How to Initialize Values to a HashSet<String[,]> in C#

If you want to initialize the HashSet with a set of known values in one step, you can use code similar to the following:

HashSet<string[,]> tblNames;
string[,] stringOne = new string[1, 1];
string[,] stringTwo = new string[1, 1];

tblNames = new HashSet<string[,]> { stringOne, stringTwo };

This is called a collection initializer. It was introduced in C# 3.0, and includes the following elements:

  • A sequence of object initializers, enclosed by { and } tokens and separated by commas.
  • Element initializers, each of which specifies an element to be added to the collection object.

I want to write java code and assume that it is the same as in c#

HashSet<T> tblNames = new HashSet<T>(); // T should be same

HashSet<string> tblNames = new HashSet<string> ();
tblNames.add("a");
tblNames.add("b");
tblNames.add("c");

or simply

HashSet<string> tblNames = new HashSet<string> {"a", "b", "c"};

or

HashSet<String[,]> tblNames = new HashSet<String[,]> ();
// same logic you can add array here
tblNames.add(stringArray1);
tblNames.add(stringArray2);

or again

HashSet<String[,]> tblNames = new HashSet<String[,]> {stringArray1, strginArray2};

tblNames.Add(new [,] { { "0", "tblAssetCategory" }});