gpt4 book ai didi

Java集合查询: creating array of mkdir commands

转载 作者:行者123 更新时间:2023-12-01 14:09:20 24 4
gpt4 key购买 nike

我有一个StringLinkedHashSet,如下所示:

Set<String> dirSet = new LinkedHashSet<String>();

上面Set中有12个String元素,如下:

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/

通过迭代 Set 并借助 String 的帮助,我能够达到 dir5 级别,然后进入一级,即直到 baseDir1/subDir/。 split() 方法来创建 token 。

但是,当我再次必须升级时(baseDir2、baseDir3 等),我无法应对

我怎样才能实现这个目标?

感谢您的阅读!

最佳答案

关于Java集合查询: creating array of mkdir commands,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18660149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com