<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recursive on Evan Hoffman</title><link>https://evan.wtf/tags/recursive/</link><description>Recent content in Recursive on Evan Hoffman</description><generator>Hugo</generator><language>en-US</language><copyright>Evan Hoffman</copyright><lastBuildDate>Sat, 17 Apr 2010 23:42:16 +0000</lastBuildDate><atom:link href="https://evan.wtf/tags/recursive/index.xml" rel="self" type="application/rss+xml"/><item><title>Code to flatten a list in Java, with and without recursion</title><link>https://evan.wtf/2010/04/17/code-to-flatten-a-list-in-java-with-and-without-recursion/</link><pubDate>Sat, 17 Apr 2010 23:42:16 +0000</pubDate><guid>https://evan.wtf/2010/04/17/code-to-flatten-a-list-in-java-with-and-without-recursion/</guid><description>&lt;p&gt;Recently had someone ask me to solve this problem: assume you have a list of objects, some of which may be lists of arbitrary depths. Write a function to return the list &amp;ldquo;flattened,&amp;rdquo; so sublists are all in the &amp;ldquo;main&amp;rdquo; list. I solved it recursively pretty easily, but it took some thought to do it without recursion. My solutions are below.&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;package com.evanhoffman.listflattener;&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;import java.util.LinkedList;&#10;import java.util.List;&#10;import java.util.ListIterator;&lt;/p&gt;&#10;&lt;p&gt;import org.apache.log4j.BasicConfigurator;&#10;import org.apache.log4j.Logger;&lt;/p&gt;</description></item></channel></rss>