Duplicate Elements in an Array
Here we have implemented List Interface and Hashtable Collection Framework from util package. It is not necessary to use List Interface instead we can choose any other Interfaces according to how we want our data to be stored or we can direcly print the duplicate numbers directly.
Now, Let me explain how Hashtables works we have to implement Hashtable with atleast two arguments one is for Index as Integer and another one is for our values to be stored in that Index.
Here we have iterated through all the values one by one to check whether the values are present in Hashtable or not. If the value is not in the table we have to insert those values in the Hashtable and if the value is present in the table either we can print the values or omit or to store the data for future use. Now we can print Original values using print statement. Instead of using Numbers we also can use String, Characters as our values.
Java Code
Here we have implemented List Interface and Hashtable Collection Framework from util package. It is not necessary to use List Interface instead we can choose any other Interfaces according to how we want our data to be stored or we can direcly print the duplicate numbers directly.
Now, Let me explain how Hashtables works we have to implement Hashtable with atleast two arguments one is for Index as Integer and another one is for our values to be stored in that Index.
Here we have iterated through all the values one by one to check whether the values are present in Hashtable or not. If the value is not in the table we have to insert those values in the Hashtable and if the value is present in the table either we can print the values or omit or to store the data for future use. Now we can print Original values using print statement. Instead of using Numbers we also can use String, Characters as our values.
Java Code
0 Comments