[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Arraylist into  public void add(String fileName) {

Posted on 2004-03-31
6
Medium Priority
?
402 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
[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
  • 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 500 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

649 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