4 回答
12345678_0001
TA貢獻1802條經驗 獲得超5個贊
public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};private static final String[] VALUES = new String[] {"AB","BC","CD","AE"};new String[];
private static final Set<String> VALUES = new HashSet<String>(Arrays.asList(
new String[] {"AB","BC","CD","AE"}));Collections.unmodifiableSet
VALUES.contains(s)
最新情況:Set.of.
private static final Set<String> VALUES = Set.of( "AB","BC","CD","AE");
三國紛爭
TA貢獻1804條經驗 獲得超7個贊
ArrayUtils.contains
public static boolean contains(Object[] array, Object objectToFind)
falsenull.
例子:
String[] fieldsToInclude = { "id", "name", "location" };if ( ArrayUtils.contains( fieldsToInclude, "id" ) ) {
// Do some stuff.}
慕雪6442864
TA貢獻1812條經驗 獲得超5個贊
public static <T> boolean contains(final T[] array, final T v) {
for (final T e : array)
if (e == v || v != null && v.equals(e))
return true;
return false;}改進:
v != nullarrayforcontains()
public static <T> boolean contains2(final T[] array, final T v) {
if (v == null) {
for (final T e : array)
if (e == null)
return true;
}
else {
for (final T e : array)
if (e == v || v.equals(e))
return true;
}
return false;}添加回答
舉報
0/150
提交
取消
