Get the first element of the Set collection

HashSet set = new HashSet<>();
set.add(“f”);
set.add(“a”);
set.add(“b”);
set.add(“d”);
// enhance for Loop through
for (String string: set) { System.out.println(string); }

set.iterator().next() to
get the first element

Simple and rude

Guess you like

Origin blog.csdn.net/qq_40145879/article/details/103400613