![](https://ld246.com/images/img-loading.svg)
Set 集合的简单使用
insertSet 方法:
public Set<String> insertSet(Set<String> stringSet) {
for (int i = 0; i < 10; i++) {
stringSet.add(i + "");
}
return stringSet;
}
deleteSet 方法:
public Set<String> deleteSet(Set<String> stringSet, String string) {
stringSet.remove(string);
return stringSet;
}
updateSet 方法:
public Set<String> updateSet(Set<String> stringSet, String deleteString, String updateString) {
stringSet.remove(deleteString);
stringSet.add(updateString);
return stringSet;
}
selectForEachSet 方法:
public void selectForEachSet(Set<String> stringSet) {
for (String s : stringSet) {
System.out.print(s + "\t");
}
}
selectIteratorSet 方法:
public void selectIteratorSet(Set<String> stringSet) {
Iterator<String> iterator = stringSet.iterator();
while (iterator.hasNext()) {
String string = iterator.next();
System.out.print(string + "\t");
}
}
Main 方法:
public static void main(String[] args) {
Set<String> stringSet = new HashSet<>();
SetTest setTest = new SetTest();
stringSet = setTest.insertSet(stringSet);
System.out.println("--------------");
setTest.selectForEachSet(stringSet);
System.out.println("--------------");
setTest.deleteSet(stringSet, "1");
setTest.selectIteratorSet(stringSet);
System.out.println("--------------");
setTest.updateSet(stringSet, "5", "15");
setTest.selectIteratorSet(stringSet);
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于