title: Split string into key-value pairs
body: <p>I have a string like this:</p>
  
  <pre><code>pet:cat::car:honda::location:Japan::food:sushi
  </code></pre>
  
  <p>Now <code>:</code> indicates key-value pairs while <code>::</code> separates the pairs.
  I want to add the key-value pairs to a map.</p>
  
  <p>I can achieve this using:</p>
  
  <pre><code>Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  String test = "pet:cat::car:honda::location:Japan::food:sushi";
  String[] test1 = test.split("::");
  
  for (String s : test1) {
      String[] t = s.split(":");
      map.put(t[0], t[1]);
  }
  
  for (String s : map.keySet()) {
      System.out.println(s + " is " + map.get(s));
  }
  </code></pre>
  
  <p>But is there an efficient way of doing this?</p>
  
  <hr>
  
  <p>I feel the code is inefficient because I have used 2 <code>String[]</code> objects and called the <code>split</code> function twice. 
  Also, I am using <code>t[0]</code> and <code>t[1]</code> which might throw an <code>ArrayIndexOutOfBoundsException</code> if there are no values.</p>