java - HashSet doesnt allow duplicates but how to write logic for allowing duplicates -
consider following program:
import java.util.*; class setdemo { public static void main(string[] args) { set s=new hashset(); s.add("ajay"); s.add(120); s.add("a"); s.add(120); system.out.println(s); } }
it outputs [a,ajay,120]
, want output contain 120
2 times. how can achieve that?
you should use hashmap
key, value pairs. or list. sets design contain unique elements.