상세 컨텐츠

본문 제목

Combining Collections

Java

by techbard 2016. 6. 29. 16:06

본문

반응형



# Map + List combining collections


import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;


public class cc

{

public static void main(String[] args)

{

Map<String, List<Integer>> testScores = new HashMap<>();

List<Integer> mikeScores = new ArrayList<>();


mikeScores.add(80);

mikeScores.add(60);

mikeScores.add(50);


testScores.put("mike", mikeScores);

printScores("mike", testScores);

}


public static void printScores(String studentName, Map<String, List<Integer>> scoreMap)

{

List<Integer> scores = scoreMap.get(studentName);


for (int score : scores)

{

System.out.println(score);

}

}

}



# 결과
80
60
50


반응형

관련글 더보기

댓글 영역