[Solved] Java File Name Printing


Loop through both the ArrayLists you have. Each ArrayList contains the file names as it is. You’ll need a nested loop (a loop inside a loop). In the core of the nested loops, you want to do a compare between current position of each ArrayList. You can use .equals() method for this. The pseudo code is something like:

//create a new ArrayList called "commonNameList"
// loop through fileNames1 with position variable "i"
    //loop through fileNames2 with position variable "j"
        //tempFileName1  = fileNames1.get(i)
        //tempFileName2 = fileNames2.get(j)
        //if tempFileName1  equals tempFileName2
            //commonNameList.add(tempFileName1)

Check these out:

http://mathbits.com/MathBits/Java/Looping/NestedFor.htm

Simple nested for loop example

How do I compare strings in Java?

2

solved Java File Name Printing