show line numbers in conde snippets

This commit is contained in:
Marcello 2023-10-20 18:22:46 +02:00
parent cd1df0e376
commit 255a68d673
82 changed files with 1249 additions and 1251 deletions

View file

@ -18,7 +18,7 @@ The **Java Collection Framework** is constituted by:
### Collection Functions
```java
```java linenums="1"
boolean add (Object o) e.g., <x>.add (<y>) //append to collection, false if fails
boolean add (int index, Object o) //insertion at given index
boolean addAll (Collection c) //appends a collection to another
@ -36,7 +36,7 @@ Iterator iterator() //returns iterator to iterate over the collection
### Collections Methods
```java
```java linenums="1"
Collection<E>.forEach(Consumer<? super T> action);
```
@ -52,7 +52,7 @@ Abstracts the problem of iterating over all the elements of a collection;
**Note**: ArrayLists can't contain *primitive* values. *Use wrapper classes* instead.
```java
```java linenums="1"
import java.util.ArrayList;
ArrayList<Type> ArrayListName = new ArrayList<Type>(starting_dim); //resizable array
ArrayList<Type> ArrayListName = new ArrayList<Type>(); //resizable array
@ -82,7 +82,7 @@ ArrayListName.forEach(item -> function(v));
To sort a collection it's items must implement `Comparable<T>`:
```java
```java linenums="1"
class ClassName implements Comparable<ClassName> {
@override
@ -99,7 +99,7 @@ Collections.sort(list); //"natural" sorting uses compareTo()
Otherwise a `Comparator()` must be implemented:
```java
```java linenums="1"
class Classname {
//code here
}