mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-06-08 18:57:12 +00:00
show line numbers in conde snippets
This commit is contained in:
parent
cd1df0e376
commit
255a68d673
82 changed files with 1249 additions and 1251 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue