Solved

Convert multi-layered arrayList to single-layered

Posted on 2001-06-16
2
224 Views
Last Modified: 2010-03-31
I have an arrayList which contains items and other arrayLists which also contain items, ie multi-layered. How can I return an arrayList which is single layered, ie contains only the items in each arrayList and contains no arrayLists?
0
Comment
Question by:ncw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 75 total points
ID: 6199027
public ArrayList createSingleLayered( ArrayList multiList )
{
  ArrayList singleList = new ArrayList();
  createSingleLayered( multiList, singleList );
  return singleList;
}
private void createSingleLayered( ArrayList multiList, ArrayList singleList )
{
  for( int i=0; i<multiList.size(); ++i )
  {
    Object obj = multiList.get( i );
    if( obj instanceof ArrayList )
    {
      createSingleLayered( (ArrayList)obj, singleList );
    }
    else
    {
      singleList.add( obj );
    }
  }
}
0
 
LVL 1

Author Comment

by:ncw
ID: 6199585
Excellent, thanks
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question