Java – create 2D hash set function

I'm trying to make a 2D hash set I have a loop through integer pairs:

ResultSet getAssociations;
        Statement getAssociationsSelect = sqlConn
                .createStatement();
        getAssociations = getAssociationsSelect
                .executeQuery("SELECT ProductId,ThemeId FROM ProductTheme");
        while(getAssociations.next()) {
            int productId1 = getAssociations.getInt(1);
            int themeId1 = getAssociations.getInt(2);
        }

When the current pair of integers does not match the previous pair, I want to store them I think a HashSet will be the best method because I can insert pairs and it won't repeat What should I do?

Solution

If you want a very simple solution to connect two keys and store the result string, for example

String newKey = String.format( "%d-%d.",productId1,themeId1 );

It will always generate a unique key for each combination

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>