text: Check duplicates in a stream of strings | Java implementation of the approach ; Function to insert the names and check whether they appear for the first time ; To store the names of the employees ; If current name is appearing for the first time ; Driver code
code: import java . util . * ; class GFG { static void insertNames ( String arr [ ] , int n ) { HashSet < String > set = new HashSet < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! set . contains ( arr [ i ] ) ) { System . out . print ( "NoNEW_LINE"); set . add ( arr [ i ] ) ; } else { System . out . print ( "YesNEW_LINE"); } } } public static void main ( String [ ] args ) { String arr [ ] = { " geeks " , " for " , " geeks " } ; int n = arr . length ; insertNames ( arr , n ) ; } }