for int i
Sets
Geht nicht!
Set<String> mySet = new HashSet<>(List.of("My", "spectacular", "Set"));
for (int i = 0; i < mySet.size(); i++) {
System.out.println(String.format("An Stelle %s befindet sich Wert %s", i + 1, mySet.get(i).substring(0,1);));
}
public static void main(String[] args) {
Set<String> mySet = new HashSet<>(List.of("My", "spectacular", "Set"));
Iterator<String> it = mySet.iterator();
int count = 1;
while(it.hasNext()){
System.out.println(String.format("An Stelle %s befindet sich Wert %s", count++, it.next()));
}
}
An Stelle 1 befindet sich Wert spectacular
An Stelle 2 befindet sich Wert Set
An Stelle 3 befindet sich Wert My