FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/collections/ListIteration.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
collections
/
ListIteration.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (35 loc) · 1.07 KB
Breadcrumbs
OnJava8-Examples
/
collections
/
ListIteration.java
Copy path
File metadata and controls
36 lines (35 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// collections/ListIteration.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import
reflection
.
pets
.*;
import
java
.
util
.*;
public
class
ListIteration
{
public
static
void
main
(
String
[]
args
) {
List
<
Pet
>
pets
=
new
PetCreator
().
list
(
8
);
ListIterator
<
Pet
>
it
=
pets
.
listIterator
();
while
(
it
.
hasNext
())
System
.
out
.
print
(
it
.
next
() +
", "
+
it
.
nextIndex
() +
", "
+
it
.
previousIndex
() +
"; "
);
System
.
out
.
println
();
// Backwards:
while
(
it
.
hasPrevious
())
System
.
out
.
print
(
it
.
previous
().
id
() +
" "
);
System
.
out
.
println
();
System
.
out
.
println
(
pets
);
it
=
pets
.
listIterator
(
3
);
while
(
it
.
hasNext
()) {
it
.
next
();
it
.
set
(
new
PetCreator
().
get
());
}
System
.
out
.
println
(
pets
);
}
}
/* Output:
Rat, 1, 0; Manx, 2, 1; Cymric, 3, 2; Mutt, 4, 3; Pug,
5, 4; Cymric, 6, 5; Pug, 7, 6; Manx, 8, 7;
7 6 5 4 3 2 1 0
[Rat, Manx, Cymric, Mutt, Pug, Cymric, Pug, Manx]
[Rat, Manx, Cymric, Rat, Rat, Rat, Rat, Rat]
*/
Back
|
FazBrowse Home
|
New Git URL