0

Guys how to output the added strings in the hashset set

Plis help https://code.sololearn.com/cC4aR1n5mBp8/?ref=app

14th Aug 2020, 3:16 PM
stephen haokip
stephen haokip - avatar
9 odpowiedzi
+ 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
14th Aug 2020, 4:59 PM
Avinesh
Avinesh - avatar
+ 1
Simple output to console: System.out.print(string) or System.out.println(string). For real world applications you'd use a logger.
14th Aug 2020, 4:54 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Thank you avinesh
14th Aug 2020, 5:02 PM
stephen haokip
stephen haokip - avatar
0
No i mean the string in the hasset set
14th Aug 2020, 4:57 PM
stephen haokip
stephen haokip - avatar
0
You can output it before adding within the for loop...
14th Aug 2020, 4:58 PM
Sandra Meyer
Sandra Meyer - avatar
0
stephen haokip you're welcome.
14th Aug 2020, 5:03 PM
Avinesh
Avinesh - avatar
0
Avinesh exacatly what i wanted. Thank you once again
14th Aug 2020, 5:04 PM
stephen haokip
stephen haokip - avatar
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
14th Aug 2020, 5:38 PM
stephen haokip
stephen haokip - avatar
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.
16th Aug 2020, 6:57 AM
Avinesh
Avinesh - avatar