0
Guys how to output the added strings in the hashset set
9 ответов
+ 1
Hashset doesn't maintain the order of insertion in the output so I have passed it to an ArrayList to achieve the same. If the order doesn't bother you then you can print the Hashset directly in the main method.
https://code.sololearn.com/c1Yw5O8hiCVP/?ref=app
+ 1
Simple output to console:
System.out.print(string) or
System.out.println(string).
For real world applications you'd use a logger.
+ 1
Thank you avinesh
0
No i mean the string in the hasset set
0
You can output it before adding within the for loop...
0
stephen haokip you're welcome.
0
Avinesh exacatly what i wanted. Thank you once again
0
Avinesh i have already created a hashset in line 15.
Why did u created again in the main method in line 31. please i want to know the reason
0
stephen haokip actually you don't have to create that in this scenario. But just in case you want to perform some other operations on the map then you might need to create a new one.
It is just like calling a method which returns a value of some type and we store it in the same type variable so that it could be manipulated later in the code.