public enum Dictionary {PLACEHOLDER1(“待更新……”,“占位符”,“形容词”),PLACEHOLDER2(“待更新……”,“占位符”,“副词”),PLACEHOLDER3(“待更新……”,“占位符”,“co
因为你需要所有匹配的对象 Enums.getIfPresent 只给你一个对象,你可以通过这样做轻松实现你的目标:
Enums.getIfPresent
public static Dictionary[] getIfPresent(String name) { List<Dictionary> response = new ArrayList<>( ); for(Dictionary d : Dictionary.values()) { if( d.getName().equalsIgnoreCase( name ) ) { response.add(d); } } return response.size() > 0 ? response.toArray( new Dictionary[response.size()] ) : null; }