Java Code Examples for java.util.Hashtable#contains()
The following examples show how to use
java.util.Hashtable#contains() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-n-IDE-for-Android File: CheckValueOfHashtableExample.java License: Apache License 2.0 | 6 votes |
public static void main(String[] args) { //create Hashtable object Hashtable ht = new Hashtable(); //add key value pairs to Hashtable ht.put("1", "One"); ht.put("2", "Two"); ht.put("3", "Three"); /* To check whether a particular value exists in Hashtable use boolean contains(Object key) method of Hashtable class. It returns true if the value is mapped to one or more keys in the Hashtable otherwise false. */ boolean blnExists = ht.contains("Two"); System.out.println("Two exists in Hashtable ? : " + blnExists); }
Example 2
Source Project: javaide File: CheckValueOfHashtableExample.java License: GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { //create Hashtable object Hashtable ht = new Hashtable(); //add key value pairs to Hashtable ht.put("1", "One"); ht.put("2", "Two"); ht.put("3", "Three"); /* To check whether a particular value exists in Hashtable use boolean contains(Object key) method of Hashtable class. It returns true if the value is mapped to one or more keys in the Hashtable otherwise false. */ boolean blnExists = ht.contains("Two"); System.out.println("Two exists in Hashtable ? : " + blnExists); }
Example 3
Source Project: MET-CS665 File: Game.java License: Apache License 2.0 | 5 votes |
/** * Check user's number with the system hidden number return the outcome with * xAyB. x is the correct guess with the same digit in the exact position. y is * the correct guess with the same digit but different position. * * @return outcome as string */ public String check(int[] digits) { int numberOfA = 0; int numberOfB = 0; // table to record any checked digit Hashtable<Integer, Integer> table = new Hashtable<Integer, Integer>(); // random numbers int[] hiddenNumbers = numbers.getNumbers(); for (int i = 0; i < digits.length; i++) { if (!table.contains(digits[i])) { boolean foundA = false; boolean foundB = false; for (int j = 0; j < hiddenNumbers.length; j++) { if (digits[i] == hiddenNumbers[j]) { // found this digit in the hidden number if (i == j) { // same position foundA = true; } else { // different position foundB = true; } } } if (foundA) { // same position numberOfA++; table.put(digits[i], digits[i]); // record this digit to avoid checking the same digit } else { if (foundB) { // different position numberOfB++; table.put(digits[i], digits[i]); // record this digit to avoid checking the same digit } } } } return numberOfA + "A" + numberOfB + "B"; }
Example 4
Source Project: MET-CS665 File: Game.java License: Apache License 2.0 | 5 votes |
/** * Check user's number with the system hidden number return the outcome with * xAyB. x is the correct guess with the same digit in the exact position. y is * the correct guess with the same digit but different position. * * @return outcome as string */ public String check(int[] digits) { int numberOfA = 0; int numberOfB = 0; // table to record any checked digit Hashtable<Integer, Integer> table = new Hashtable<Integer, Integer>(); for (int i = 0; i < digits.length; i++) { if (!table.contains(digits[i])) { boolean foundA = false; boolean foundB = false; for (int j = 0; j < numbers.length; j++) { if (digits[i] == numbers[j]) { // found this digit in the hidden number if (i == j) { // same position foundA = true; } else { // different position foundB = true; } } } if (foundA) { // same position numberOfA++; table.put(digits[i], digits[i]); // record this digit to avoid checking the same digit } else { if (foundB) { // different position numberOfB++; table.put(digits[i], digits[i]); // record this digit to avoid checking the same digit } } } } return numberOfA + "A" + numberOfB + "B"; }
Example 5
Source Project: MET-CS665 File: Game.java License: Apache License 2.0 | 5 votes |
/** * Check user's number with the system hidden number return the outcome with * xAyB. x is the correct guess with the same digit in the exact position. y is * the correct guess with the same digit but different position. * * @return outcome as string */ public String check(int[] digits) { int numberOfA = 0; int numberOfB = 0; // table to record any checked digit Hashtable<Integer, Integer> table = new Hashtable<Integer, Integer>(); // random numbers int[] hiddenNumbers = numbers.getNumbers(); for (int i = 0; i < digits.length; i++) { if (!table.contains(digits[i])) { boolean foundA = false; boolean foundB = false; for (int j = 0; j < hiddenNumbers.length; j++) { if (digits[i] == hiddenNumbers[j]) { // found this digit in the hidden number if (i == j) { // same position foundA = true; } else { // different position foundB = true; } } } if (foundA) { // same position numberOfA++; table.put(digits[i], digits[i]); // record this digit to avoid checking the same digit } else { if (foundB) { // different position numberOfB++; table.put(digits[i], digits[i]); // record this digit to avoid checking the same digit } } } } return numberOfA + "A" + numberOfB + "B"; }
Example 6
Source Project: arma-intellij-plugin File: Arma3DocumentationDownloader.java License: MIT License | 5 votes |
private void saveLookupLists() throws FileNotFoundException { PrintWriter pwCommands = new PrintWriter(commandDocPluginSaveFolder.getAbsolutePath() + "/lookup.list"); PrintWriter pwFunctions = new PrintWriter(functionDocPluginSaveFolder.getAbsolutePath() + "/lookup.list"); Hashtable<String, String> ignoredCommands = commandsDocRetriever.getIgnoredCommands(); for (PsiElementLinkType type : PsiElementLinkType.allTypes) { if (type.type.equals(PSI_ELE_TYPE_COMMAND)) { for (String command : type.linkNames) { if (!ignoredCommands.contains(command)) { pwCommands.println(command); } } } else if (type.type.equals(PSI_ELE_TYPE_FUNCTION)) { for (String function : type.linkNames) { pwFunctions.println(function); } } else { throw new IllegalStateException("dude"); } } pwCommands.flush(); pwCommands.close(); pwFunctions.flush(); pwFunctions.close(); System.out.println("\n\nSaved lookup lists"); }
Example 7
Source Project: spotbugs File: Ideas_2009_10_05.java License: GNU Lesser General Public License v2.1 | 5 votes |
public void hashtablesCantContainNull(Hashtable h) { h.put("a", null); h.put(null, "a"); h.get(null); h.contains(null); h.containsKey(null); h.containsValue(null); h.remove(null); }
Example 8
Source Project: arma-intellij-plugin File: Arma3DocumentationDownloader.java License: MIT License | 5 votes |
private void saveLookupLists() throws FileNotFoundException { PrintWriter pwCommands = new PrintWriter(commandDocPluginSaveFolder.getAbsolutePath() + "/lookup.list"); PrintWriter pwFunctions = new PrintWriter(functionDocPluginSaveFolder.getAbsolutePath() + "/lookup.list"); Hashtable<String, String> ignoredCommands = commandsDocRetriever.getIgnoredCommands(); for (PsiElementLinkType type : PsiElementLinkType.allTypes) { if (type.type.equals(PSI_ELE_TYPE_COMMAND)) { for (String command : type.linkNames) { if (!ignoredCommands.contains(command)) { pwCommands.println(command); } } } else if (type.type.equals(PSI_ELE_TYPE_FUNCTION)) { for (String function : type.linkNames) { pwFunctions.println(function); } } else { throw new IllegalStateException("dude"); } } pwCommands.flush(); pwCommands.close(); pwFunctions.flush(); pwFunctions.close(); System.out.println("\n\nSaved lookup lists"); }
Example 9
Source Project: CodenameOne File: ImageBorderAppliesToWizard.java License: GNU General Public License v2.0 | 5 votes |
private void addToListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addToListActionPerformed String name = (String)componentName.getSelectedItem(); if(name.length() > 0) { name += "."; } switch(style.getSelectedIndex()) { case 0: name += "sel#"; break; case 2: name += "press#"; break; case 3: name += "dis#"; break; } name += "border"; if(!((DefaultListModel)appliesTo.getModel()).contains(name)) { Hashtable h = res.getTheme(theme); if(h.contains(name)) { if(JOptionPane.showConfirmDialog(this, "A border already exists for this component,\ndo you want to replace it?", "Already Exists", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { return; } } ((DefaultListModel)appliesTo.getModel()).addElement(name); } }