我有3个String数组。如何检查一个人加入的群组?
String[] groupA = new String {"Tom", "Chris", "Jack", "Mary"};
String[] groupB = new String {"Chris", "Peter", "Jimmy"};
String[] groupC = new String {"Chris", "Paul", "Michael", "Jack"};
答案 0 :(得分:0)
首先将Array
转换为List
。然后使用contains
方法进行检查。
boolean joinedA = Arrays.asList(groupA).contains(name);
boolean joinedB = Arrays.asList(groupB).contains(name);
boolean joinedC = Arrays.asList(groupC).contains(name);