HashMap key with multiple values
<p>I'm trying to bind some indexes and they're corresponding strings so I tried using a HashMap like so: </p>

<pre><code>public class NewClass {
static List&lt;String&gt; referenceList = new ArrayList&lt;String&gt;();

public static void main(String[] args) {

    String x = "AGE_X";
    String y = "AGE_Y";
    //String w = "AGE_Z";
    referenceList.add(x);
    referenceList.add(y);

    String text1 = "if ( AGE_X = = 10 ){\r\n"
            + " j = 1;"
            + " AGE_X = 5 ;"
            + " if ( true ) {"
            + " m = 4 / AGE_Y ;"
            + " }"
            + " }";
    detectEquals(text1);
}

public static String detectEquals(String text) {
    String a = null;
    // text = TestSplitting.addDelimiters(text);
    String[] newString = text.split(" ");
    List&lt;String&gt; test = Arrays.asList(newString);
    StringBuilder strBuilder = new StringBuilder();
    HashMap&lt;String, List&lt;Integer&gt;&gt; signs = new HashMap&lt;String, List&lt;Integer&gt;&gt;();
    List&lt;Integer&gt; refList = new ArrayList&lt;Integer&gt;();
    int index = 0;

    for (int i = 0; i &lt; test.size(); i++) {
        a = test.get(i).trim();
        //System.out.println("a=" + a);
        strBuilder.append(a);   
        index = strBuilder.length() - a.length();

        if (a.equals("if") || a.equals("=")) {         
            refList.add(index);
            // System.out.println(refList);
            signs.put(a, refList);
            refList = new ArrayList&lt;Integer&gt;();

            System.out.println(signs);
        }
    }
    return a;
}
}
</code></pre>

<p>But I am not having any luck with it. I'm trying to get every "if" and "=" from that string(text1) and map them together but it seems I am doing something wrong, because my output looks like this :</p>

<blockquote>
  <p>{if=[0]}</p>
  
  <p>{if=[0], ==[8]}</p>
  
  <p>{if=[0], ==[9]}</p>
  
  <p>{if=[0], ==[15]}</p>
  
  <p>{if=[0], ==[23]}</p>
  
  <p>{if=[26], ==[23]}</p>
  
  <p>{if=[26], ==[36]}</p>
</blockquote>

<p>I am looking for something like : </p>

<blockquote>
  <p>if=[0,26] and = =[8,9,15,23,23,36]</p>
</blockquote>

<p>I need some help with figuring out where I'm making a mistake here? Or am I just not printing them out properly? Any help would be greatly appreciated.</p>

<p>Thank you,</p>

<p>Daniel</p>
