title: How to do PHP explode(", "), list(), foreach() in Java style
body: <p>I have PHP code and i am translating it to Java, but how do we do PHP like explode(), list(), foreach() with Java? Following PHP code are my example problems:</p>
  
  <pre><code>1. PHP:
    /** 
     * @return: Array
     */
      public function parse($digest) 
      {
        $array = array();
        $parts = explode(", ", $digest);
  
        foreach ($parts as $x) 
        {
         $bits = explode("=", $x);
         $data[$bits[0]] = str_replace('"','', $bits[1]);
        }
  
        return $array;
      }
  
  Java (updated):
    private String[] parse(String digest)
    {
      Map&lt;String,String&gt; array = new HashMap&lt;String, String&gt;();
      String[] parts = digest.split(", ");
  
      for (String x:parts)
      {
        String[] bits = x.split("=");
        array.put(bits[0], bits[1].replace( '"','' )); // later will apply regex
      }
  
      return array; // incompatible types
    }
  
  
  
  2. PHP:
    /** 
     * @return: String
     */
    public function response($text, $user, $pass, $httpmethod, $uri) 
    {        
        list($dummy_digest, $value) = split(' ', $text, 2);    
        $x = $this-&gt;parse($value);
  
        $realm = $x['realm'];
        if ($x['qop'] == 'auth') 
        {
          ...
        }
  
        $base  = "{$realm}, {$x['realm']}";
        //"Digest username="1", realm="1", nonce="xxxxxx", uri="abc", response="abc", qop="auth", algorithm="MD5", cnonce="", nc="1"";
        return $base;
  
    }
  
  
  Java problem:
     public String response(String text, String user, String pass, String httpmethod, String uri)
     {  
        // how to do such list() like php?
        return "Digest username="1", realm="1", nonce="xxxxxx", uri="abc", response="abc", qop="auth", algorithm="MD5", cnonce="", nc="1"";
     } 
  </code></pre>