5 Replies Latest reply: Jun 28, 2010 9:26 AM by 843793 RSS

    How can I copy a hashmap to an array?

    843793
      Hi
      In the following code I have tried to copy a hash-map to array of map entries. Because I need to compare each value by next and previous values and detect local maximums.
      But when I run this I get java.lang.NullPointerException in toArray(a) function.
      Please help me. What Do I have to do to create an array of map entries of a hash-map?
      Map.Entry<String, Float>[] a = null;
      HashMap.entrySet().toArray(a);
      for (int i = 1; i < a.length-1 ; i++) {
           if (a.getValue()>a[i-1].getValue() && a[i].getValue()>a[i+1].getValue()) {
                System.out.println(a[i].getKey());
           }
      }
      By the way, If exist another solution to comparing three adjacent values in hash-map, please tell me.
      Thanks for any help.