15 lines
1.2 KiB
Plaintext
15 lines
1.2 KiB
Plaintext
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
|
\PYG{n}{ArrayList}\PYG{o}{\PYGZlt{}}\PYG{n}{Integer}\PYG{o}{\PYGZgt{}}\PYG{+w}{ }\PYG{n}{list}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{k}{new}\PYG{+w}{ }\PYG{n}{ArrayList}\PYG{o}{\PYGZlt{}}\PYG{n}{Integer}\PYG{o}{\PYGZgt{}}\PYG{p}{();}
|
|
|
|
\PYG{c+c1}{// looping though an ArrayList using the Iterator class}
|
|
\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Iterator}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{.}\PYG{n+na}{iterator}\PYG{p}{();}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{.}\PYG{n+na}{hasNext}\PYG{p}{();)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
|
\PYG{+w}{ }\PYG{n}{Integer}\PYG{+w}{ }\PYG{n}{value}\PYG{+w}{ }\PYG{o}{=}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Integer}\PYG{p}{)}\PYG{+w}{ }\PYG{n}{i}\PYG{p}{.}\PYG{n+na}{next}\PYG{p}{();}
|
|
\PYG{+w}{ }\PYG{c+c1}{// do some stuff}
|
|
\PYG{p}{\PYGZcb{}}
|
|
|
|
\PYG{c+c1}{// looping though an ArrayList using a For-Each loop}
|
|
\PYG{k}{for}\PYG{+w}{ }\PYG{p}{(}\PYG{n}{Integer}\PYG{+w}{ }\PYG{n}{i}\PYG{+w}{ }\PYG{p}{:}\PYG{+w}{ }\PYG{n}{list}\PYG{p}{)}\PYG{+w}{ }\PYG{p}{\PYGZob{}}
|
|
\PYG{+w}{ }\PYG{c+c1}{// do some stuff}
|
|
\PYG{p}{\PYGZcb{}}
|
|
\end{Verbatim}
|