Skip to content

Commit

Permalink
pm2
Browse files Browse the repository at this point in the history
- java iterator
  • Loading branch information
xy-241 committed Jun 29, 2024
1 parent a66784a commit 73f8006
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions content/Java/Java.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,28 @@ Author Profile:
tags:
- java
Creation Date: 2023-07-20T21:02:30+08:00
Last Date: 2023-12-15T23:31:58+08:00
Last Date: 2024-06-29T17:05:51+08:00
References:
---
## Abstract
- Strongly typed with [[Static Typing]]
- [[OOP]]
- [[Functional Programming]] (not very elegant)
---
- A [[OOP]] language that is[[Datatype#Statically Typed]] & [[Datatype#Strongly Typed]]. It also provides a [[Function|functional]] interface but it isn't very elegant




## Java Iterator
---
- An [[OOP#OOP Object]] of the `java.util.Iterator` [[OOP#OOP Class]] that can be used to **loop through collections** like `ArrayList` and `HashSet`

>[!code] Obtaining a Java Iterator
> `Iterator<T> it = cars.iterator();`, where `cars` is an instance of Java collections.
>[!code] Get the first element of a collection using Java iterator
>`it.next();` returns the first element of a collection, where `it` is a Java iterator.
>[!code] Loop through a collection using Java iterator
> `while(it.hasNext()) {System.out.println(it.next());}`, where `it` is a Java iterator.
>[!code] Remove an element from a collection using Java iterator
> `it.remove();`, where `it` is a Java iterator.

0 comments on commit 73f8006

Please sign in to comment.