Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.szaf.org!news.gnuher.de!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Philipp Kraus Newsgroups: comp.lang.java.programmer Subject: hash map / collection choice Date: Sun, 27 Apr 2014 21:58:25 +0200 Organization: 1&1 Internet AG Lines: 54 Message-ID: NNTP-Posting-Host: p4fc61336.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: online.de 1398628705 8354 79.198.19.54 (27 Apr 2014 19:58:25 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Sun, 27 Apr 2014 19:58:25 +0000 (UTC) User-Agent: Unison/2.1.10 Xref: csiph.com comp.lang.java.programmer:28271 Hello, I need help to create a data structure. I have got a class class myEdge { private int m_edgeid = 0; …. @Override public int compareTo(myEdgep_edgelink) { if (m_edgeid > p_edgelink.m_edgeid) return 1; if (m_edgeid < p_edgelink.m_edgeid) return -1; return 0; } @Override public boolean equals(Object p_object) { if ( (p_object == null) || (!(p_object instanceof myEdge)) ) return false; return this.m_edgeid == ((myEdge)p_object).m_edgeid; } @Override public int hashCode() { return m_edgeid; } } The edge ID is always unique. So I would like to create a collection in which I can do something like myEdge x = edgecollection.get( searching edge id ) So the collection stores the edge objects and I can get an object with the internal id. The collection should use the the edgeid value to identify the object. A set should be the correct structure, but I can not get the object itself of the map without iteration over all items. A HashMap needs a key, value pair, so I need also a key class which stores the edge id (redundant data). I'm a little bit uncertain, which collection is the correct choice. Thanks a lot Phil