<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: iterate code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 07:53:01 GMT</pubDate>
    <description>DZone Snippets: iterate code</description>
    <item>
      <title>Recursively dump imbricated Map of Maps</title>
      <link>http://snippets.dzone.com/posts/show/4531</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    public void dumpMapOfMap(Map map) {&lt;br /&gt;        Set s = map.entrySet();&lt;br /&gt;        Iterator sit = s.iterator();&lt;br /&gt;        boolean isFirst = true;&lt;br /&gt;&lt;br /&gt;        while (sit.hasNext()) {&lt;br /&gt;            Map.Entry elem = (Map.Entry)sit.next();&lt;br /&gt;            String key = (String)elem.getKey();&lt;br /&gt;            Object value = elem.getValue();&lt;br /&gt;&lt;br /&gt;            if (value instanceof String) {&lt;br /&gt;                // recursivity stop condition&lt;br /&gt;                System.out.print(key);&lt;br /&gt;                System.out.print(" : ");&lt;br /&gt;                System.out.println(value);&lt;br /&gt;            } else {&lt;br /&gt;                if (!isFirst) {&lt;br /&gt;                    System.out.println("");&lt;br /&gt;                } else {&lt;br /&gt;                    isFirst = false;&lt;br /&gt;                }&lt;br /&gt;                System.out.println(key);&lt;br /&gt;                Map valueMap = (Map)elem.getValue();&lt;br /&gt;                dumpMapOfMap(valueMap);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Sep 2007 12:58:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4531</guid>
      <author>Archanciel (Jean-Pierre Schnyder)</author>
    </item>
    <item>
      <title>Advanced iterating in Ruby with 'enumerator'</title>
      <link>http://snippets.dzone.com/posts/show/176</link>
      <description>require 'enumerator'&lt;br /&gt;&lt;br /&gt;ary = [ 1, 2, 3, 4 ]&lt;br /&gt;&lt;br /&gt;# iterate over two elements at a time&lt;br /&gt;ary.each_slice(2) { |a,b| p [a, b] }&lt;br /&gt;&lt;br /&gt;# iterate over every pair of consecutive pair of numbers&lt;br /&gt;ary.each_cons(2) { |a, b| p [a, b] }&lt;br /&gt;&lt;br /&gt;# An Enumerable::Enumerator object can be created as well,&lt;br /&gt;# that mixes in Enumerable, for further processing:&lt;br /&gt;ary.enum_for(:each_cons, 2).map { |a,b| a + b  } # =&gt; [3, 5, 7]&lt;br /&gt;</description>
      <pubDate>Sat, 16 Apr 2005 00:19:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/176</guid>
      <author>flori (Florian Frank)</author>
    </item>
  </channel>
</rss>
