title: How to convert a HashMap to a JavaPairRDD, in Spark?
body: <p>I am very new to Apache Spark. I am trying to create a <code>JavaPairRdd</code> from <code>HashMap</code>. I have a <code>HashMap</code> of type <code>&lt;String,&lt;Integer,Integer&gt;&gt;</code>
  How can I convert it into a <code>JavaPairRdd</code>? I have pasted my code below:</p>
  
  <pre><code>HashMap&lt;String, HashMap&lt;Integer,String&gt;&gt; canlist =
      new HashMap&lt;String, HashMap&lt;Integer,String&gt;&gt;();
  
  for (String key : entityKey)
  {
      HashMap&lt;Integer, String&gt; clkey = new HashMap&lt;Integer, String&gt;();
      int f=0;
      for (String val :mentionKey)
      {
          //do something
          simiscore = (longerLength - costs[m.length()]) / (double) longerLength;
  
          if (simiscore &gt; 0.6) {
              clkey.put(v1,val);
              System.out.print(
                  " The mention  " + val + " added to link entity  " + key);
              }
              f++;
              System.out.println("Scan Completed");
      }
      canlist.put(key,clkey);
      JavaPairRDD&lt;String, HashMap&lt;Integer, String&gt;&gt; rad;
      rad = context.parallelize(scala.collection.Seq(toScalaMap(canlist)));
  
  }
  public static &lt;String,Object&gt; Map&lt;String,Object&gt; toScalaMap(HashMap&lt;String,Object&gt; m) {
      return (Map&lt;String,Object&gt;) JavaConverters.mapAsScalaMapConverter(m).asScala().toMap(
              Predef.&lt;Tuple2&lt;String,Object&gt;&gt;conforms()
      );}
  }
  </code></pre>