나는 주어진 세트에서 고유 한 멤버로 팀을 구성하려고합니다. 이것은 내가 지금까지 가지고있는 것이다. 나는이 프로그램을 실행할 때주어진리스트에서 뚜렷한 선택하기
import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
/* Putting all team-mates in HashMap */
HashMap<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
map.put("d", 4);
/* Printing out the random name and the Unique number with it*/
List<Integer> valuesList = new ArrayList<Integer>(map.values());
List<String> keyList = new ArrayList<String>(map.keySet());
System.out.println("The Team members are :");
for (int i = 0; i < 3; i++)
{
int randomIndex = new Random().nextInt(valuesList.size());
Integer randomValue = valuesList.get(randomIndex);
String randomKey = keyList.get(randomIndex);
System.out.println(randomValue+" "+randomKey);
}
}
}
, 나는 내 목록에서 중복을 얻을 내가 Collections.shuffle (valuesList)를 사용합니까?
감사합니다.
'import java.lang. *;'not required ...,'java.lang.Exception' ??? – Mordechai