Code: Select all
static {
final String hexCharacters = "0123456789ABCDEFabcdef"; //NON-NLS
final Set tempHexSet = new HashSet();
for (char c : hexCharacters.toCharArray()) {
tempHexSet.add(c);
}
final Set hexSet = Collections.unmodifiableSet(tempHexSet);
}
Code: Select all
private static final Set hexSet
= Collections.unmodifiableSet(
new HashSet(
"0123456789ABCDEFabcdef".toCharArray()
)
);
Code: Select all
private static final Set hexSet = Collections.unmodifiableSet(
new HashSet("0123456789ABCDEFabcdef"
.chars()
.boxed()
.collect(Collectors.toList())
);
Nachtrag:
Der Sinn dieses Satzes besteht darin, einen statischen Satz zu initialisieren, damit ich so etwas schreiben kann:
Code: Select all
boolean isValidCharacter(char c) {
return hexSet.contains(c);
}
Code: Select all
return "0123456789ABCDEFabcdef".contains(c);
Mobile version