44 lines
1.5 KiB
Markdown
44 lines
1.5 KiB
Markdown
Java collections for primitives (currently only int) released under [MIT](https://opensource.org/licenses/MIT) license.
|
|
|
|
*IntList* and *LongList* are implementations of lists that store primitive integers/longs. The ints/longs are stored in an int/long array and the class takes care of growing the array as needed. You can trim the list to reduce the memory overhead. No dependencies.
|
|
|
|
The lists support the following operations:
|
|
|
|
* add/remove elements via single and bulk operations
|
|
* replace elements
|
|
* sort and shuffle
|
|
>* the lists know whether or not they are sorted and can leverage that knowledge for searching (binary search), union and intersection
|
|
* search for elements
|
|
* union, intersection, retainIf, retainAll removeIf, removeAll
|
|
* clear and trim are separate methods, so that the list can be re-used without having to reallocate memory
|
|
* stream support
|
|
* the lists are serializable and cloneable
|
|
* the list are **not** thread-safe
|
|
|
|
#Examples
|
|
|
|
```java
|
|
import org.lucares.collections.IntList;
|
|
|
|
public class Example {
|
|
public static void main(final String[] args) {
|
|
final IntList list = IntList.of(1, 3, 5);
|
|
System.out.println(list + " is sorted: " + list.isSorted());
|
|
|
|
list.insert(2, 7);
|
|
System.out.println(list + " is sorted: " + list.isSorted());
|
|
|
|
list.sort();
|
|
System.out.println(list + " is sorted: " + list.isSorted());
|
|
}
|
|
}
|
|
|
|
```
|
|
Running this program gives the following output:
|
|
|
|
```
|
|
[1, 3, 5] is sorted: true
|
|
[1, 3, 7, 5] is sorted: false
|
|
[1, 3, 5, 7] is sorted: true
|
|
```
|