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.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -