Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is <em>not</em> a good idea. Map keys must be immutable to work properly, and yours are not.</p> <p>What are you really trying to do? When I see people doing things like this with data structures, it makes me think that they really need an object but have forgotten that Java's an object-oriented language.</p> <p>Looks like you want a crude dictionary to translate between languages. I'd create a <code>LanguageLookup</code> class that embedded those Maps and provide some methods to make it easier for users to interact with it. Better abstraction and encapsulation, more information hiding. Those should be your design objectives. Think about how to add other languages besides English and French so you can use it in other contexts. </p> <pre><code>public class LanguageLookup { private Map&lt;String, String&gt; dictionary; public LanguageLookup(Map&lt;String, String&gt; words) { this.dictionary = ((words == null) ? new HashMap&lt;String, String&gt;() : new HashMap&lt;String, String&gt;(words)); } public String lookup(String from) { return this.dictionary.get(from); } public boolean hasWord(String word) { return this.dictionary.containsKey(word); } } </code></pre> <p>In your case, it looks like you want to translate an English word to French and then see if the French dictionary contains that word:</p> <pre><code>Map&lt;String, String&gt; englishToFrenchWords = new HashMap&lt;String, String&gt;(); englishToFrenchWords.put("one", "une"); Map&lt;String, String&gt; frenchToEnglishWords = new HashMap&lt;String, String&gt;(); frenchToEnglishWords.put("une", "one"); LanguageLookup englishToFrench = new LanguageLookup(englishToFrenchWords); LanguageLookup frenchToEnglish = new LanguageLookup(frenchToEnglishWords); String french = englishToFrench.lookup("one"); boolean hasUne = frenchToEnglish.hasWord(french); </code></pre>
    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. 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