如何检查一个人加入的群组?

时间:2017-05-07 13:56:06

标签: java arrays

我有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"};

1 个答案:

答案 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);