-2

我可以像这样转换数组:

String [] [] friend = new String [] [] {{{robert, marie}, {jhony, eva}, ​​{mike, laura}, ​​{adrian, rachel}, {kristen, anthony}};

随机选择两对情侣,结果是这样的:

String [] [] friend = new String [] [] {{{robert, marie}, {adrian, rachel}};

以后这样做:

String [] friendfin = new String [] {{robert, marie, adrian, rachel}};

任何人都可以帮助我使用此代码...谢谢

4

1 回答 1

0

这是一种方法:

String[][] friends = new String[][]{
   {robert, marie}, {jhony, eva}, ​​{mike, laura},
   ​​{adrian, rachel}, {kristen, anthony}
};
List<String> list = new ArrayList<String>();
for(String[] array : friends)
{
    for(String friend : array) list.add(friend);
}
Collections.shuffle(list);
String[] friendfin = new String[list.length];
list.toArray(friendfin); // fill the array
friendfin = Arrays.copyOf(friendfin, 4);
于 2013-02-11T20:51:55.693 回答