How to avoid inserting duplicate values in a HashMap? -


मान लें कि हमारे पास है: map hm = new hashMap ();

डुप्लिकेट मान (एपीप्सी) इस हाशमैप में?

मुझे लगता है कि आप जावा में कोडिंग कर रहे हैं, इसलिए:

  यदि (! MyMap.containsKey (myKey)) {myMap.put (myKey, myValue); }   

हैशमैप के साथ अच्छी बात यह है कि में की विधि की संख्या को ध्यान में रखते हुए निरंतर समय (या निरंतर परिशोधित समय) लेता है अपने नक्शे में तत्व ताकि आप इसे उस समय की परेशानियों के बिना कॉल कर सकते हैं!

यदि आप किसी दूसरी भाषा का उपयोग करते हैं, तो तर्क समान ही रहता है।

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

javascript - What is an alternative to using getElementByClass for hiding multiple elements? -

javascript - Making the first column of a table fixed on horizontal scroll -