我在groovy中有以下数组:
test = [Andrew-PAR, Jackson-CDG, Jilly-MAD, Mike-CDG, Tim-AGP]
并且也遵循枚举
NAME_PLACE("Andrew-PAR, Jackson-CDG, Brian-NY")
获取Andrew-PAR, Jackson-CDG, Brian-NY
我需要的是什么
*必须找出枚举中不在数组中的值' test'
即输出为'Brian-NY'
我尝试<enum returned values> - test
来查找输出 - 但它显示了枚举中的整个值,如Andrew-PAR, Jackson-CDG, Brian-NY
枚举代码:
public enum StudentDetails {
NAME_PLACE("Andrew-PAR, Jackson-CDG, Brian-NY"),
NAME_COURSE("TEST1, TEST2"),
private final String studentdetails
StudentDetails (String studentdetails) {
this.studentdetails = studentdetails
}
public String getstudent() {
return studentdetails
}
}
获取枚举值的代码:
def student = StudentDetails.values().find {
val.equalsIgnoreCase(it.name())
} ?.getstudent()
找到差异:
def diff = student - test
答案 0 :(得分:2)
试试这个:
public enum StudentDetails {
NAME_PLACE("Andrew-PAR, Jackson-CDG, Brian-NY"),
NAME_COURSE("TEST1, TEST2"),
private final String studentdetails
StudentDetails (String studentdetails) {
this.studentdetails = studentdetails
}
public String getstudent() {
return studentdetails
}
public String value(){
return studentdetails
}
}
def test = ["Andrew-PAR", "Jackson-CDG", "Jilly-MAD", "Mike-CDG", "Tim-AGP"]
println StudentDetails.NAME_PLACE.value().split(",")*.trim()-test