I have been looking at this for awhile now but I cant really seem to find much about it online. I have a JTree and a list of strings. I want to search just the lowest levels of the JTree(so not every node in the tree is searched, just the lowest nodes) for each of the strings and add the string to a list if the string i am searching for is present in the path of the lowest node
something like this
public List<String> searchLowestNodes(List<String> wordsToSearchFor){
List<String> matches = new ArrayList<>;
for(String word: wordsToSearchFor){
// i do not know how to get the lowest node for each path
if(path.contains(word)){
matches.add(word);
}
//keep looping for all paths
}
return matches;
}
Does anybody know how this can be done?
EDIT: Tree example
Root
-assignment1
--paul
---example.java
--john
---example.java
-assignment2
--a2
---sean
----assignment.java
---mark
----assignment.java
so given the following tree it should only search the following paths for the words
root>assignment1>paul>example.java
root>assignment1>john>example.java
root>assignment2>a2>sean>assignment.java
root>assignment2>a2>mark>assignment.java
i do not want to add
root>assignment1
root>assignment1>paul
...