ࡱ> CEB bjbjVV 0,<<44wwwww,L p#www   ww   'Kاz0 >#v#4K#wKX v#4 =: Computer Programming I Instructor: Greg ShawPRIVATE  COP 2210 ArrayLists of Primitive Types Wrapper Classes Java has a class known as a wrapper class associated with each of the primitive types. Primitive TypeWrapper ClassdoubleDoubleintIntegerbooleanBooleancharCharacter To create an ArrayList to store primitive type values, we use the wrapper class. For example, to create an ArrayList to store int values: ArrayList list = new ArrayList() ; Storing a Primitive Type Value in an ArrayList Since Java 1.5 (aka: Java 5), we have been able to store primitive type values in ArrayLists simply by passing them as arguments to the add() and set() methods. For example, here is a loop that stores the ints 1 through 10 in elements 0 through 9 of an ArrayList: ArrayList list = new ArrayList() ; for (int i = 1 ; i <= 10 ; i++) { list.add( i ) ; } What actually happens when we add a primitive type value to an ArrayList is that an object of the associated wrapper class - with the primitive value wrapped inside - is automatically created and added to the list. This is known as autoboxing, but maybe should be called autowrapping. Retrieving a Primitive Type Value from an ArrayList Since Java 1.5, ArrayList method get() returns the primitive type value "wrapped inside" the object. (This is known as autounboxing, but maybe should be called autounwrapping.) For example, to compute the sum of all the ints in the list created above, all we need to do is: int sum = 0 ; for (int i = 0 ; i < list.size() ; i++) { int number = list.get( i ) ; sum = sum + number ; // autounboxing! } 34<=>?SU`bstuv}~ujuj_UGUhRGhRG6CJOJQJhRGCJOJQJhf5CJOJQJhRG5CJOJQJhI"hI"5CJOJQJ"hRGhRG56CJOJQJaJhd56CJ$OJQJhf56CJ$OJQJhfCJOJQJhf56CJ%jhf@CJOJQJUhf@CJOJQJ"jhf@CJOJQJUhf@CJOJQJ?STUstu}}$ 0p @ h*$^ha$gdRG$ 0p @ *$a$$ & F 0p @ *$^`a$$ 08p @ 80*$^8`0a$ $ 0*$a$ 0*$$a$$*$a$    k{kdT$$Ifl0C @ t0644 layt $ 0p @ $*$Ifa$gd      / 0 ? @   3 4 5 < C S U  ʶʶ~~p~p~fhECJOJQJhEBhEB6CJOJQJhEBCJOJQJhdCJOJQJhf5CJOJ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ayt $$If!vh5 5@ #v #v@ :V l t065 5@ ayt $$If!vh5 5@ #v #v@ :V l t065 5@ ayt $$If!vh5 5@ #v #v@ :V l t065 5@ ayt ^ 666666666vvvvvvvvv666666>6666666666666666666666666666666666666666666666666hH6666666666666666666666666666666666666666666666666666666666666666662 0@P`p2( 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p8XV~_HmH nH sH tH 8`8 Normal_HmH sH tH P@P  Heading 1$$*$@&a$56CJ OJQJDA D Default Paragraph FontVi@V  Table Normal :V 44 la (k (No List jj RG Table Grid7:V0PK![Content_Types].xmlj0Eжr(΢Iw},-j4 wP-t#bΙ{UTU^hd}㨫)*1P' ^W0)T9<l#$yi};~@(Hu* Dנz/0ǰ $ X3aZ,D0j~3߶b~i>3\`?/[G\!-Rk.sԻ..a濭?PK!֧6 _rels/.relsj0 }Q%v/C/}(h"O = C?hv=Ʌ%[xp{۵_Pѣ<1H0ORBdJE4b$q_6LR7`0̞O,En7Lib/SeеPK!kytheme/theme/themeManager.xml M @}w7c(EbˮCAǠҟ7՛K Y, e.|,H,lxɴIsQ}#Ր ֵ+!,^$j=GW)E+& 8PK!Ptheme/theme/theme1.xmlYOo6w toc'vuر-MniP@I}úama[إ4:lЯGRX^6؊>$ !)O^rC$y@/yH*񄴽)޵߻UDb`}"qۋJחX^)I`nEp)liV[]1M<OP6r=zgbIguSebORD۫qu gZo~ٺlAplxpT0+[}`jzAV2Fi@qv֬5\|ʜ̭NleXdsjcs7f W+Ն7`g ȘJj|h(KD- dXiJ؇(x$( :;˹! I_TS 1?E??ZBΪmU/?~xY'y5g&΋/ɋ>GMGeD3Vq%'#q$8K)fw9:ĵ x}rxwr:\TZaG*y8IjbRc|XŻǿI u3KGnD1NIBs RuK>V.EL+M2#'fi ~V vl{u8zH *:(W☕ ~JTe\O*tHGHY}KNP*ݾ˦TѼ9/#A7qZ$*c?qUnwN%Oi4 =3ڗP 1Pm \\9Mؓ2aD];Yt\[x]}Wr|]g- eW )6-rCSj id DЇAΜIqbJ#x꺃 6k#ASh&ʌt(Q%p%m&]caSl=X\P1Mh9MVdDAaVB[݈fJíP|8 քAV^f Hn- "d>znNJ ة>b&2vKyϼD:,AGm\nziÙ.uχYC6OMf3or$5NHT[XF64T,ќM0E)`#5XY`פ;%1U٥m;R>QD DcpU'&LE/pm%]8firS4d 7y\`JnίI R3U~7+׸#m qBiDi*L69mY&iHE=(K&N!V.KeLDĕ{D vEꦚdeNƟe(MN9ߜR6&3(a/DUz<{ˊYȳV)9Z[4^n5!J?Q3eBoCM m<.vpIYfZY_p[=al-Y}Nc͙ŋ4vfavl'SA8|*u{-ߟ0%M07%<ҍPK! ѐ'theme/theme/_rels/themeManager.xml.relsM 0wooӺ&݈Э5 6?$Q ,.aic21h:qm@RN;d`o7gK(M&$R(.1r'JЊT8V"AȻHu}|$b{P8g/]QAsم(#L[PK-![Content_Types].xmlPK-!֧6 +_rels/.relsPK-!kytheme/theme/themeManager.xmlPK-!Ptheme/theme/theme1.xmlPK-! ѐ' theme/theme/_rels/themeManager.xml.relsPK]  ,     / ?  3 8@0(  B S  ?  )IRcfpxz{qsz}15%(47cf33333333346uvcp46uvcp < C)8Ui-83~UF>;)8@GNmrK bPPztdhd`NCg:|u̒0^`0.0h^h`5679;<B*CJ8H*OJQJS*TXo(+h8^8`CJ0OJQJ^Jo(hHFh^`OJQJ^Jo(hHoh ^ `OJQJo(hHh ^ `OJQJo(hHhx^x`OJQJ^Jo(hHohH^H`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHoh^`OJQJo(hH0h^h`5679;<B*CJ8H*OJQJS*TXo(+^`56.0^`0.hh^h`CJ OJQJo(l^`56.@@^@`.0^`0o(. mrKbPPuCCg<hd`@GF>;Ui- А        I"="?g?EBRGUbiV6(dE~`f @`@UnknownG* Times New Roman5Symbol3. * Arial?= * Courier NewEMonotype Sorts;WingdingsA BCambria Math"qhFF  24 3QHP?RG2!xxArrayLists and Primitive TypesThe KingFIU-SCS4         Oh+'0x  4 @ LX`hp ArrayLists and Primitive Types The King Normal.dotmFIU-SCS2Microsoft Office Word@G@Eקz@Eקz՜.+,0 hp|    ArrayLists and Primitive Types Title  !"#$%&'()*+,-./013456789;<=>?@ADRoot Entry FɘاzFData 1Table($WordDocument0,SummaryInformation(2DocumentSummaryInformation8:CompObjy  F'Microsoft Office Word 97-2003 Document MSWordDocWord.Document.89q