Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple of things to be corrected here, I'll attempt to address the ones I see.</p> <p><em>Firstly</em>, the Java standard is to use lowercase names for variables. Makes it very difficult to read otherwise, as everything looks like a type name.</p> <p><em>Second</em>, Never use <code>new String()</code> to create a new string Object. Java strings are immutable, and the JVM maintains a pool of strings used in the application. A string created with <code>new String()</code> will create a brand new copy from the string passed to that constructor, which is <strong>not</strong> drawn from that pool, but separately allocated (so in effect, unnecessarily allocating more memory for a string object which may already exist in the pool). Instead just pass the strings like <code>"bob"</code> and <code>"BobsWindshield"</code>.</p> <p><em>And finally</em>, to answer the question directly, since your exact use-case is uncertain, your solution might not even need a Hash. You might be able to get away with using an <a href="http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html" rel="nofollow"><code>ArrayList</code></a> instead, if you just care about plain simple storage of multiple objects of the same type.</p> <p>However, in order to use a <a href="http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html" rel="nofollow"><code>HashMap</code></a>, you need to keep in mind that a Hash / Map is a collection of Key-Value pairs. Your current implementation is essentially non-sensical if your intention is to store and index multiple <code>PlayerNames</code> objects. Do this instead:</p> <pre><code>HashMap&lt;String, PlayerNames&gt; playerTempNeutral = new HashMap&lt;String, PlayerNames&gt;(); playerTempNeutral.put("Bob", new PlayerNames("Bob", "BobsWindshield"); playerTempNeutral.put("Ron", new PlayerNames("Ron", "RonsDoor"); </code></pre> <p>In this example, "Bob" or "Ron" is the key, and the corresponding <code>PlayerNames</code> object is the value relating to that key.</p> <p>In order to get one of those objects from the collection, you simply do so using the key (or "index value", I guess you could call it):</p> <pre><code>PlayerNames bob = playerTempNeutral.get("bob"); </code></pre> <p>And of course, once you have your <code>bob</code> object, you can play with it as needed (ex: <code>bob.TagName</code>).</p> <p>I suspect this may not necessarily be your use-case, so you'll have to elaborate more if you need additional information.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload