我有一个LinkedHashSet
如下String
:
Set<String> dirSet = new LinkedHashSet<String>();
上面有12个String
元素Set
如下:
root/dir1/dir2/dir3/dir4/dir5/baseDir1/
root/dir1/dir2/dir3/dir4/dir5/baseDir1/subDir/
root/dir1/dir2/dir3/dir4/dir5/baseDir2/
root/dir1/dir2/dir3/dir4/dir5/baseDir2/subDir/
root/dir1/dir2/dir3/dir4/dir5/baseDir3/
root/dir1/dir2/dir3/dir4/dir5/baseDir3/subDir/
root/dir1/dir2/dir3/dir4/dir5/baseDir4/
root/dir1/dir2/dir3/dir4/dir5/baseDir4/subDir/
root/dir1/dir2/dir3/dir4/dir5/baseDir5/
root/dir1/dir2/dir3/dir4/dir5/baseDir5/subDir/
root/dir1/dir2/dir3/dir4/dir5/baseDir6/
root/dir1/dir2/dir3/dir4/dir5/baseDir6/subDir/
我想编写一个方法来迭代上面Set
的方法,该方法的输出是String
Array
包含创建上述目录结构的命令。
输出String
Array
应包含String
以下元素:
mkdir root/
mkdir root/dir1/
mkdir root/dir1/dir2/
mkdir root/dir1/dir2/dir3/
mkdir root/dir1/dir2/dir3/dir4/
mkdir root/dir1/dir2/dir3/dir4/dir5/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir1/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir1/subDir/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir2/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir2/subDir/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir3/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir3/subDir/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir4/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir4/subDir/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir5/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir5/subDir/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir6/
mkdir root/dir1/dir2/dir3/dir4/dir5/baseDir6/subDir/
我能够达到dir5
水平,然后baseDir1/subDir/
通过迭代 Set 并借助String.split()
方法来创建令牌,直到达到一个水平。
但是,当我再次必须升级时(baseDir2、baseDir3 等),我无法解决问题。
我怎样才能做到这一点?
谢谢阅读!