コレクションフレームワーク 第2章

₇⩦ၥ㢟㻌㻌
➨❶
ࢥࣞࢡࢩࣙࣥࣇ࣮࣒࣮ࣞ࣡ࢡ
ᮏ❶࡛Ꮫ⩦ࡋࡓෆᐜࢆ☜ㄆࡋࡲࡍࠋ㸦ᇶᮏ㸧ࠊ㸦ᛂ⏝㸧ࠊ㸦Ⓨᒎ㸧ࡢ㡰࡟ゎࡁࡲࡍࠋ㸦ᇶᮏ㸧
ࡣࡍ࡭࡚ゎࡁࡲࡋࡻ࠺ࠋ
㻞㻚㻝
ࣜࢫࢺ㸦ᇶᮏ㸧㻌
$UUD\/LVW ࢡࣛࢫࢆ฼⏝ࡋ࡚㏣ຍࡋࡓᩥᏐิࢆ⾲♧ࡍࡿࣉࣟࢢ࣒ࣛࢆసᡂࡋࡲࡍࠋᐇ⾜⤖ᯝࢆ
ཧ⪃࡟ࡋ࡚ࠊḟࡢせ௳ࢆ‶ࡓࡍࡼ࠺࡟ 7HVW$UUD\/LVW ࢡࣛࢫࢆ᏶ᡂࡉࡏ࡚ࡃࡔࡉ࠸ࠋ
䖃
せ௳
䕺
$UUD\/LVW ࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡋࠊᩥᏐิࢆ ࡘ㏣ຍࡍࡿ
䕺
$UUD\/LVW ࢜ࣈࢪ࢙ࢡࢺࡢせ⣲ࢆ⾲♧ࡍࡿ
䖃
$UUD\/LVW ࢜ࣈࢪ࢙ࢡࢺ࡟㏣ຍࡍࡿᩥᏐิ
㡰␒
ᩥᏐิ
ࡾࢇࡈ
ࡳ࠿ࢇ
࣓ࣟࣥ
ࡾࢇࡈ
䖃
ࢯ࣮ࢫࣉࣟࢢ࣒ࣛ
7HVW$UUD\/LVWMDYD㸦ᮍ᏶ᡂ㸧
SXEOLFFODVV7HVW$UUD\/LVW^
SXEOLFVWDWLFYRLGPDLQ 6WULQJ>@DUJV ^
$UUD\/LVW࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡍࡿ
$UUD\/LVW࢜ࣈࢪ࢙ࢡࢺ࡟ᩥᏐิࢆࡘ㏣ຍࡍࡿ
ᣑᙇIRUᩥࢆ⏝࠸࡚$UUD\/LVW࢜ࣈࢪ࢙ࢡࢺࡢせ⣲ࢆ⾲♧ࡍࡿ
`
`
㻌
䖃
ᐇ⾜⤖ᯝ
!MDYD7HVW$UUD\/LVW
ࡾࢇࡈ
ࡳ࠿ࢇ
࣓ࣟࣥ
ࡾࢇࡈ
!
㻝㻤㻌
➨ 㻞 ❶㻌 䝁䝺䜽䝅䝵䞁䝣䝺䞊䝮䝽䞊䜽㻌㻌
㻞㻚㻞
ࣜࢫࢺ㸦ᇶᮏ㸧㻌
$UUD\/LVW ࢜ࣈࢪ࢙ࢡࢺ࡟㏣ຍࡋࡓ *RRGV ࢜ࣈࢪ࢙ࢡࢺࡢ᝟ሗࢆ⏬㠃࡟⾲♧ࡍࡿࣉࣟࢢ࣒ࣛࢆ
సᡂࡋࡲࡍࠋᐇ⾜⤖ᯝࢆཧ⪃࡟ࡋ࡚ࠊḟࡢせ௳ࢆ‶ࡓࡍࡼ࠺࡟ 7HVW$UUD\/LVW ࢡࣛࢫࢆ᏶ᡂࡉࡏ
࡚ࡃࡔࡉ࠸ࠋ
䖃
せ௳
䕺
*RRGV ࢜ࣈࢪ࢙ࢡࢺࢆ ࡘ⏕ᡂࡋࠊ$UUD\/LVW ࢜ࣈࢪ࢙ࢡࢺ࡟㏣ຍࡍࡿ
䕺
$UUD\/LVW ࢜ࣈࢪ࢙ࢡࢺ࡟㏣ຍࡋࡓ *RRGV ࢜ࣈࢪ࢙ࢡࢺࢆฟຊࡍࡿ
䖃
*RRGV ࢜ࣈࢪ࢙ࢡࢺ࡟タᐃࡍࡿ್
࢜ࣈࢪ࢙ࢡࢺ
*RRGV ࢜ࣈࢪ࢙ࢡࢺ *RRGV ࢜ࣈࢪ࢙ࢡࢺ *RRGV ࢜ࣈࢪ࢙ࢡࢺ *RRGV ࢜ࣈࢪ࢙ࢡࢺ 㻌
ᒓᛶ
್
QDPH
ࡾࢇࡈ
SULFH
QDPH
ࡾࢇࡈ
SULFH
QDPH
ࡳ࠿ࢇ
SULFH
QDPH
ࡾࢇࡈ
SULFH
㻌
㻝㻥㻌
₇⩦ၥ㢟㻌㻌
䖃
ࢯ࣮ࢫࣉࣟࢢ࣒ࣛ
*RRGVMDYD㸦ᐃ⩏῭㸧
SXEOLFFODVV*RRGV^
SULYDWH6WULQJQDPHၟရྡ
SULYDWHLQWSULFH༢౯
ࢥࣥࢫࢺࣛࢡࢱ
SXEOLF*RRGV ^
`
SXEOLF*RRGV 6WULQJQDPHLQWSULFH ^
WKLVQDPH QDPH
WKLVSULFH SULFH
`
ၟရྡࢆྲྀᚓࡍࡿ
SXEOLF6WULQJJHW1DPH ^
UHWXUQQDPH
`
ၟရྡࢆタᐃࡍࡿ
SXEOLFYRLGVHW1DPH 6WULQJQDPH ^
WKLVQDPH QDPH
`
༢౯ࢆྲྀᚓࡍࡿ
SXEOLFLQWJHW3ULFH ^
UHWXUQSULFH
`
༢౯ࢆタᐃࡍࡿ
SXEOLFYRLGVHW3ULFH LQWSULFH ^
WKLVSULFH SULFH
`
ၟရྡࠊ༢౯ࢆ⾲♧ࡍࡿ
SXEOLFYRLGGLVSOD\ ^
6\VWHPRXWSULQWOQ ၟရྡQDPH༢౯SULFH `
`
7HVW$UUD\/LVWMDYD㸦ᮍ᏶ᡂ㸧
SXEOLFFODVV7HVW$UUD\/LVW^
SXEOLFVWDWLFYRLGPDLQ 6WULQJ>@DUJV ^
$UUD\/LVW࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡍࡿ
$UUD\/LVW࢜ࣈࢪ࢙ࢡࢺ࡟*RRGV࢜ࣈࢪ࢙ࢡࢺࢆ㏣ຍࡍࡿ
ᣑᙇIRUᩥࢆ⏝࠸࡚$UUD\/LVW࢜ࣈࢪ࢙ࢡࢺࡢせ⣲ࢆ⾲♧ࡍࡿ
`
`
㻞㻜㻌
➨ 㻞 ❶㻌 䝁䝺䜽䝅䝵䞁䝣䝺䞊䝮䝽䞊䜽㻌㻌
㻌
䖃
ᐇ⾜⤖ᯝ
!MDYD7HVW$UUD\/LVW
ၟရྡࡾࢇࡈ౯᱁
ၟရྡࡾࢇࡈ౯᱁
ၟရྡࡳ࠿ࢇ౯᱁
ၟရྡࡾࢇࡈ౯᱁
!
㻌
㻞㻝㻌
₇⩦ၥ㢟㻌㻌
㻞㻚㻟
ࣜࢫࢺ㸦ᛂ⏝㸧㻌
࣮࢝ࢺ࡟ၟရࢆධࢀࠊ⾲♧ࡍࡿࣉࣟࢢ࣒ࣛࢆసᡂࡋࡲࡍࠋḟࡢ௙ᵝ࡜ᐇ⾜⤖ᯝ࡟ᇶ࡙࠸࡚ &DUW
ࢡࣛࢫࢆᐃ⩏ࡋ࡚ࡃࡔࡉ࠸ࠋ
䖃
ࢡࣛࢫࡢ௙ᵝ
7HVW&DUW
PDLQ DUJV6WULQJ>@ &DUW
QDPH6WULQJ
JRRGV/LVW$UUD\/LVW*RRGV!
&DUW QDPH6WULQJ JHW1DPH 6WULQJ
JHW*RRGV/LVW $UUD\/LVW*RRGV!
DGG JRRGV*RRGV JHW$PRXQW LQW
GLVSOD\ *RRGV
QDPH6WULQJ
SULFHLQW
*RRGV *RRGV QDPH6WULQJSULFHLQW JHW1DPH 6WULQJ
VHW1DPH QDPH6WULQJ JHW3ULFH LQW
VHW3ULFH SULFHLQW GLVSOD\ 㻌
㻌
㻞㻞㻌
➨ 㻞 ❶㻌 䝁䝺䜽䝅䝵䞁䝣䝺䞊䝮䝽䞊䜽㻌㻌
ࢡࣛࢫྡ &DUW
ᴫせ
ᒓᛶ
࣮࢝ࢺࢆ⾲ࡍࠋ
SULYDWH6WULQJQDPH
㢳ᐈྡ
SULYDWH$UUD\/LVW*RRGV!JRRGV/LVW
ၟရࣜࢫࢺ
SXEOLF&DUW 6WULQJQDPH ㄝ᫂ ᘬᩘࡢ್ࢆ㢳ᐈྡ࡟௦ධࡋࠊJRRGV/LVW ࢆึᮇ໬ࡍࡿࢥࣥࢫࢺ
ࣛࢡࢱࠋ
SXEOLF6WULQJJHW1DPH ㄝ᫂
QDPH ࢆ㏉ࡍࠋ
SXEOLF$UUD\/LVW*RRGV!JHW*RRGV/LVW ㄝ᫂
᧯స
JRRGV/LVW ࢆ㏉ࡍࠋ
SXEOLFYRLGDGG *RRGVJRRGV ㄝ᫂
ᘬᩘࡢ್ࢆ JRRGV/LVW ࡟㏣ຍࡍࡿࠋ
SXEOLFLQWJHW$PRXQW ㄝ᫂
JRRGV/LVW ࡟᱁⣡ࡉࢀ࡚࠸ࡿ *RRGV ࢜ࣈࢪ࢙ࢡࢺࡢ༢౯ࡢྜィ
ࢆ㏉ࡍࠋ
SXEOLFYRLGGLVSOD\ ㄝ᫂
㢳ᐈྡࠊ⌧ᅾ࣮࢝ࢺ࡟ධࡗ࡚࠸ࡿၟရࡢ᝟ሗࠊྜィ㔠㢠ࢆ⾲♧
ࡍࡿࠋ
㻌
㻌
㻞㻟㻌
₇⩦ၥ㢟㻌㻌
䖃
ࢯ࣮ࢫࣉࣟࢢ࣒ࣛ
*RRGVMDYD㸦ᐃ⩏῭㸧
㻌
㻌
SXEOLFFODVV*RRGV^
SULYDWH6WULQJQDPHၟရྡ
SULYDWHLQWSULFH༢౯
ࢥࣥࢫࢺࣛࢡࢱ
SXEOLF*RRGV ^
`
SXEOLF*RRGV 6WULQJQDPHLQWSULFH ^
WKLVQDPH QDPH
WKLVSULFH SULFH
`
ၟရྡࢆྲྀᚓࡍࡿ
SXEOLF6WULQJJHW1DPH ^
UHWXUQQDPH
`
ၟရྡࢆタᐃࡍࡿ
SXEOLFYRLGVHW1DPH 6WULQJQDPH ^
WKLVQDPH QDPH
`
༢౯ࢆྲྀᚓࡍࡿ
SXEOLFLQWJHW3ULFH ^
UHWXUQSULFH
`
༢౯ࢆタᐃࡍࡿ
SXEOLFYRLGVHW3ULFH LQWSULFH ^
WKLVSULFH SULFH
`
ၟရྡࠊ༢౯ࢆ⾲♧ࡍࡿ
SXEOLFYRLGGLVSOD\ ^
6\VWHPRXWSULQWOQ ၟရྡQDPH༢౯SULFH `
`
㻞㻠㻌
➨ 㻞 ❶㻌 䝁䝺䜽䝅䝵䞁䝣䝺䞊䝮䝽䞊䜽㻌㻌
7HVW&DUWMDYD㸦ᐃ⩏῭㸧
SXEOLFFODVV7HVW&DUW^
SXEOLFVWDWLFYRLGPDLQ 6WULQJ>@DUJV ^
&DUW࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡍࡿ
&DUWFDUW QHZ&DUW 6X]XNL &DUW࢜ࣈࢪ࢙ࢡࢺ࡟ၟရࢆ㏣ຍࡍࡿ
FDUWDGG QHZ*RRGV ࡾࢇࡈ FDUWDGG QHZ*RRGV ࡾࢇࡈ FDUWDGG QHZ*RRGV ࡳ࠿ࢇ 6\VWHPRXWSULQWOQ &DUW࢜ࣈࢪ࢙ࢡࢺࡢ᝟ሗࢆ⾲♧ࡍࡿ
FDUWGLVSOD\ `
`
㻌
䖃
ᐇ⾜⤖ᯝ
!MDYD7HVW&DUW
࣮࢝ࢺ࡟ࡾࢇࡈࢆ㏣ຍࡋࡲࡋࡓࠋ
࣮࢝ࢺ࡟ࡾࢇࡈࢆ㏣ຍࡋࡲࡋࡓࠋ
࣮࢝ࢺ࡟ࡳ࠿ࢇࢆ㏣ຍࡋࡲࡋࡓࠋ
6X]XNLࡉࢇࡢ࣮࢝ࢺ
ၟရྡࡾࢇࡈ༢౯
ၟရྡࡾࢇࡈ༢౯
ၟရྡࡳ࠿ࢇ༢౯
ྜィ㸸෇
!
㻞㻡㻌
₇⩦ၥ㢟㻌㻌
㻞㻚㻠
ࢭࢵࢺ㸦ᇶᮏ㸧㻌
+DVK6HW ࢡࣛࢫࢆ฼⏝ࡋ࡚㏣ຍࡋࡓᩥᏐิࢆฟຊࡍࡿࣉࣟࢢ࣒ࣛࢆసᡂࡋࡲࡍࠋᐇ⾜⤖ᯝࢆཧ
⪃࡟ࡋ࡚ࠊḟࡢせ௳ࢆ‶ࡓࡍࡼ࠺࡟ 7HVW+DVK6HW ࢡࣛࢫࢆ᏶ᡂࡉࡏ࡚ࡃࡔࡉ࠸ࠋ
䖃
せ௳
䕺
+DVK6HW ࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡋࠊᩥᏐิࢆ ࡘ㏣ຍࡍࡿ
䕺
+DVK6HW ࢜ࣈࢪ࢙ࢡࢺ࡟㏣ຍࡋࡓᩥᏐิࢆ⾲♧ࡍࡿ
㻌
䖃
+DVK6HW ࢜ࣈࢪ࢙ࢡࢺ࡟㏣ຍࡍࡿᩥᏐิ
㡰␒
ᩥᏐิ
ࡾࢇࡈ
ࡳ࠿ࢇ
࣓ࣟࣥ
ࡾࢇࡈ
䖃
ࢯ࣮ࢫࣉࣟࢢ࣒ࣛ
7HVW+DVK6HWMDYD㸦ᮍ᏶ᡂ㸧
SXEOLFFODVV7HVW+DVK6HW^
SXEOLFVWDWLFYRLGPDLQ 6WULQJ>@DUJV ^
+DVK6HW࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡍࡿ
+DVK6HW࢜ࣈࢪ࢙ࢡࢺ࡟ᩥᏐิࢆࡘ㏣ຍࡍࡿ
ᣑᙇIRUᩥࢆ⏝࠸࡚+DVK6HW࢜ࣈࢪ࢙ࢡࢺࡢせ⣲ࢆ⾲♧ࡍࡿ
`
`
䖃
ᐇ⾜⤖ᯝ
!MDYD7HVW+DVK6HW
ࡳ࠿ࢇ
ࡾࢇࡈ
࣓ࣟࣥ
!
㻌
㻌
㻞㻢㻌