0

I have been working on this String Split method and the special for loop that I am currently trying to get to properly work does not seem to be working no matter what I do. It keeps printing just the parent directory and not the lower directories.

 public boolean moveDown(String file) {
    String[] input = file.split("\\\\"); // breaks string into individual file names
    ArrayList<Node> children = current.getChildren();
    for (Node c : children) {
        if (file.equals(c.getName())) {
            current = c;
            location += "\\" + current.getName();
            return true;
            if(file.equals(c.getName(file.split()))){
                current = c;
                location+= "\\" + current.getName();
                return true;
            }
        }

    }
    return false;
}
3
Contributors
2
Replies
17
Views
2 Years
Discussion Span
Last Post by stultuske
0

That fragment of code makes no sense withoutall the other code that you didn't post here, so it's impossible to understand. You have shared variables, classes, and parameters that we know nothing about, and a method that seems to be all about its side effects.
In particular line 9 looks weird. How does getName handle a parameter that's an array of Strings?

Edited by JamesCherrill

0
String[] input = file.split("\\\\")

have you checked the result of this, the size of input?
might be it "splits" to one element, being the original String.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.