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
Solved

Arraylist into  public void add(String fileName) {

Posted on 2004-03-31
6
382 Views
Last Modified: 2010-03-31
I have the files in an arraylist. How would I get them from the arraylist into the code below, this first section, is the bottom section of the code following it.



 public void add(String fileName) {
        listOfFiles.add(fileName);
    }


public class ListOfFiles implements Enumeration {

    private List listOfFiles = new ArrayList(); // Start with an empty list by default
    private int current = 0;

    public ListOfFiles() {
    }
    public ListOfFiles(List listOfFiles) {
        this.listOfFiles = listOfFiles;
    }

    public boolean hasMoreElements() {
        if (current < listOfFiles.size())
            return true;
        else
            return false;
    }

    public Object nextElement() {
        InputStream in = null;
        if (!hasMoreElements())
            throw new NoSuchElementException("No more files.");
        else {
            String nextElement = (String)listOfFiles.get(current);
            current++;
            try {
                in = new FileInputStream(nextElement);
            } catch (FileNotFoundException e) {
                System.err.println("ListOfFiles: Can't open " + nextElement);
            }
        }
        return in;
    }

    public void add(String fileName) {
        listOfFiles.add(fileName);
    }
}
0
Comment
Question by:Drop_of_Rain
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 10726960
public void add(ArrayList fileNames) {
        for (int i=0;i<filesNames.size();i++) {
            lstOfFiles.add((String) fileNames.elementAt(i));
        }
    }
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 10727052
listOfFiles.addAll(otherlist);
0
 

Author Comment

by:Drop_of_Rain
ID: 10727217
That is a big difference of simplicity. They both work so how do I handle this question reqarding the points. I prefer objects answer though.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 18

Expert Comment

by:bobbit31
ID: 10727236
give points to objects, his answer is clearly better
0
 

Author Comment

by:Drop_of_Rain
ID: 10727358
objects I really like the way you approach your code writing, direct but simple. I hope I learn from your example.

Rgds,
Christopher
0
 
LVL 92

Expert Comment

by:objects
ID: 10727412
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 52
ejb stateless example 2 25
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 57
Chrome and Firefox Java 5 51
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

828 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