Question

I just now started working with hashsets and I am trying to print it out but all it prints out is its location i tried Iterator and .toString() here is my code :

char [] a = RandomWord.toCharArray();
        HashSet<char[]>  set = new HashSet<char[]>();
        set.add(a);
          Iterator<char[]> itr = set.iterator();
            while(itr.hasNext()){
                System.out.println(" Iterating over HashSet in Java current object: " + itr.next().toString());
            }
    }
Was it helpful?

Solution

You have to print the content of your array. Arrays.toString(char[] a) will do that for you :

System.out.println(" Iterating over HashSet in Java current object: " + Arrays.toString(itr.next()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top