HashMap<Character, Integer> part(int idx) {
   if (idx < left.size()) {
     return left;
   } else {
     return right;
   }
 }
Esempio n. 2
0
 public static void main(String[] args) {
   HashMap hm = new HashMap();
   hm.put(1, 20);
   hm.put(2, 30);
   hm.put(5, 50);
   System.out.println("Value for the Key 1: " + hm.get(1));
   System.out.println("Value for the Key 5: " + hm.get(5));
   System.out.println("Size : " + hm.size());
 }
Esempio n. 3
0
  /**
   * Save the state of this <tt>HashSet</tt> instance to a stream (that is, serialize this set).
   *
   * @serialData The capacity of the backing <tt>HashMap</tt> instance (int), and its load factor
   *     (float) are emitted, followed by the size of the set (the number of elements it contains)
   *     (int), followed by all of its elements (each an Object) in no particular order.
   */
  private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
    // Write out any hidden serialization magic
    s.defaultWriteObject();

    // Write out HashMap capacity and load factor
    s.writeInt(map.capacity());
    s.writeFloat(map.loadFactor());

    // Write out size
    s.writeInt(map.size());

    // Write out all elements in the proper order.
    for (Iterator i = map.keySet().iterator(); i.hasNext(); ) s.writeObject(i.next());
  }
Esempio n. 4
0
 /**
  * Returns the number of elements in this set (its cardinality).
  *
  * @return the number of elements in this set (its cardinality).
  */
 public int size() {
   return map.size();
 }