“CollectionUtils” Methods
CollectionUtils.chunk(collection, [size=1])
sourcemaven central repository
collection
of elements split into groups the length of size
. If collection
can't be split evenly, the final chunk will be the remaining elements.1.0.2
collection
(Collections): The collection to process.size
(number): The length of each chunk.collection
of chunks.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.chunk(null, 2));
// => []
List<String> input = Arrays.asList("a", "b", "c", "d");
int size = 2;
List<List<String>> result = CollectionUtils.chunk(input, 2);
System.out.println(result);
// => [["a", "b"], ["c", "d"]]
}
}
Try in REPLCollectionUtils.compact(collection)
sourcemaven central repository
collection
with all falsey
values removed. The values (false
, null
, 0
, ""
, NaN
) are falsey
.1.0.2
collection
(Collections): The collection to compact.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.compact(null));
// => []
List<String> input = Arrays.asList("a", null, "", "d");
List<String> result = CollectionUtils.compact(input);
System.out.println(result);
// => ["a", "d"]
}
}
Try in REPLCollectionUtils.concat(collection, [values])
sourcemaven central repository
collection
concatenating collection
with any additional collection
.1.0.2
collection
(Collections): The collection to concatenate.[values]
(...Collections): The collection to concatenate.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.concat(null, Arrays.asList(1, 2, 3)));
// => [1, 2, 3]
List<Integer> input = Arrays.asList(1);
List<Integer> result = CollectionUtils.concat(input, Arrays.asList(2, 3, 4), Arrays.asList(5, 6, null));
System.out.println(result);
// => [1, 2, 3, 4, 5, 6]
}
}
Try in REPLCollectionUtils.difference(collection, [values])
sourcemaven central repository
collection
with elements from the first collection
that are not in any of the other given collections
.1.0.2
collection
(Collections): The collection to inspect.[values]
(...Collections): The collection of values to exclude.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.compact(null));
// => []
List<String> input = Arrays.asList("a", null, "", "d");
List<String> result = CollectionUtils.compact(input);
System.out.println(result);
// => ["a", "d"]
}
}
Try in REPLCollectionUtils.differenceBy(collection, [predicate], [values])
sourcemaven central repository
collection
with elements from the first collection
that are not in any of the other given collections
. The comparison is performed based on a criterion derived using the provided predicate function.1.0.2
collection
(Collections): The collection to inspect.[predicate]
(Predicate): The function invoked per iteration.[values]
(...Collections): The collection to exclude.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.differenceBy(null, x -> x > 2 , Arrays.asList(1, 2)));
// => []
System.out.println(CollectionUtils.differenceBy(Arrays.asList(1, 2), x -> x > 2 , null));
// => [1, 2]
List<Double> input = Arrays.asList(2.1, 1.2);
List<Double> exclude = Arrays.asList(2.3, 3.4);
List<Double> result = CollectionUtils.differenceBy(input, x -> x < 2, exclude);
System.out.println(result);
// => [1.2]
}
}
Try in REPLCollectionUtils.differenceWith(collection, [comparator], [values])
sourcemaven central repository
collection
and multiple other collections
, based on a custom comparator.1.0.2
collection
(Collections): The collection to inspect.[comparator]
(BiPredicate): The comparator invoked per element.[values]
(...Collections): The collection to exclude.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.differenceWith(null, Objects::equals, Arrays.asList(1, 2)));
// => []
System.out.println(CollectionUtils.differenceWith(Arrays.asList(1, 2), Objects::equals, null));
// => [1, 2]
List<String> input = Arrays.asList("Apple", "Banana", "Cherry");
List<String> exclude = Arrays.asList("banana", "cherry");
List<String> result = CollectionUtils.differenceWith(input, String::equalsIgnoreCase, exclude);
System.out.println(result);
// => ["Apple"];
}
}
Try in REPLCollectionUtils.drop(collection, [n])
sourcemaven central repository
collection
with n elements dropped from the beginning.1.0.2
collection
(Collections): The collection to query.[n]
(int): The number of elements to drop.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.drop(null, 1));
// => []
List<Integer> list = Arrays.asList(1, 2, 3);
List<Integer> result = CollectionUtils.drop(list, 2);
System.out.println(result);
// => [3]
}
}
Try in REPLCollectionUtils.dropRight(collection, [n])
sourcemaven central repository
collection
with n elements dropped from the end.1.0.2
collection
(Collections): The collection to query.[n]
(int): The number of elements to drop.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.dropRight(null, 1));
// => []
List<Integer> list = Arrays.asList(1, 2, 3);
List<Integer> result = CollectionUtils.dropRight(list, 2);
System.out.println(result);
// => [1]
}
}
Try in REPLCollectionUtils.dropRightWhile(collection, [predicate])
sourcemaven central repository
collection
with elements dropped from the end until.1.0.2
collection
(Collections): The collection to query.[predicate]
(Predicate): The function invoked per iteration.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.dropRightWhile(null, (Integer num) -> num.compareTo(3) < 0));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.dropRightWhile(collection, (Integer num) -> num.compareTo(3) > 0);
System.out.println(result);
// => [1, 2, 3]
}
}
Try in REPLCollectionUtils.dropWhile(collection, [predicate])
sourcemaven central repository
collection
with elements dropped from beginning until the predicate returns false
.1.0.2
collection
(Collections): The collection to query.[predicate]
(Predicate): The function invoked per iteration.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.dropWhile(null, (Integer num) -> num.compareTo(3) < 0));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4);
List<Integer> result = CollectionUtils.dropWhile(collection, (Integer num) -> num.compareTo(3) < 0);
System.out.println(result);
// => [3, 4]
}
}
Try in REPLCollectionUtils.fill(list, value, [start], [end])
sourcemaven central repository
list
with value
from start to end.1.0.2
list
(List): The list to modify.[value]
(<T>): The value to fill into the list.[start]
(int): The start position.[end]
(int): The end position.list
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.fill(null, 7, 0, 4));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.fill(collection, 0, 1, 4);
System.out.println(result);
// => [1, 0, 0, 0, 5]
}
}
Try in REPLCollectionUtils.findIndex(collection, [predicate], [fromIndex])
sourcemaven central repository
index
of the first element in the collection
that satisfies the provided predicate
, starting from the specified index
.1.0.2
collection
(Collections): The collection to inspect.[predicate]
(Predicate): The function invoked per iteration.[fromIndex]
(int): The index to search from.-1
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.findIndex(null, (Integer x) -> x == 3, 0));
// => -1
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
int result = CollectionUtils.findIndex(collection, (Integer x) -> x.equals(3), 0);
System.out.println(result);
// => 2
}
}
Try in REPLCollectionUtils.findLastIndex(collection, [predicate], [fromIndex])
sourcemaven central repository
index
of the last element in the collection
that satisfies the provided predicate
, starting from the specified index
.1.0.2
collection
(Collections): The collection to inspect.[predicate]
(Predicate): The function invoked per iteration.[fromIndex]
(int): The index to search from.-1
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.findLastIndex(null, (Integer x) -> x == 3, 0));
// => -1
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
int result = CollectionUtils.findLastIndex(collection, (Integer x) -> x.equals(3), 4);
System.out.println(result);
// => 2
}
}
Try in REPLCollectionUtils.head(collection)
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to query.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.head(null));
// => Optional.empty()
List<String> input = Arrays.asList(null, "second");
System.out.println(CollectionUtils.head(input));
// => Optional.empty()
List<Integer> collection = Arrays.asList(1, 2, 3);
System.out.println(CollectionUtils.head(collection));
// => Optional[1]
}
}
Try in REPLCollectionUtils.flatten(collection)
sourcemaven central repository
collection
a single level deep.1.0.2
collection
(Collections): The collection to flatten.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.flatten(null));
// []
List<Object> collection = Arrays.asList(Arrays.asList(1, 2, null), Arrays.asList(3, 4, null));
List<Object> result = CollectionUtils.flatten(collection);
System.out.println(result);
// => [1, 2, null, 3, 4, null]
}
}
Try in REPLCollectionUtils.flattenDeep(collection)
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to flatten.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.flattenDeep(null));
// []
List<Object> collection = Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, Arrays.asList(4, 5)));
// [[1,2], [3, [4,5]]]
List<Object> result = CollectionUtils.flattenDeep(collection);
System.out.println(result);
// => [1, 2, 3, 4, 5]
}
}
Try in REPLCollectionUtils.flattenDepth(collection, [depth])
sourcemaven central repository
collection
up to depth times.1.0.2
collection
(Collections): The collection to flatten.depth
(int): The maximum recursion depth.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.flattenDepth(null, 1));
// []
List<Object> collection = Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, Arrays.asList(4, 5)));
// [[1,2], [3, [4,5]]]
List<Object> result = CollectionUtils.flattenDepth(collection, 1);
System.out.println(result);
// => [1, 2, 3, [4, 5]]
}
}
Try in REPLCollectionUtils.fromPairs(pairs)
sourcemaven central repository
Map
composed of key-value pairs.1.0.2
pairs
(List<List<T>>): The list of key-value pairs to convert into a map.map
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.fromPairs(null));
// => empty Map
List<List<String>> pairs = Arrays.asList(
Arrays.asList("key1", "value1"),
Arrays.asList("key2"),
Arrays.asList("key3", "value3")
);
Map<String, String> result = CollectionUtils.fromPairs(pairs);
System.out.println(result);
// => Map of { "key1"="value1", "key3"="value3" }
}
}
Try in REPLCollectionUtils.indexOf(collection, [value])
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to inspect.[value]
(<T>): The value to search for.-1
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.indexOf(null, 3));
// => -1
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
int result = CollectionUtils.indexOf(collection, 3);
System.out.println(result);
// => 2
}
}
Try in REPLCollectionUtils.indexOf(collection, [value], [fromIndex])
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to inspect.[value]
(<T>): The value to search for.[fromIndex]
(int): The index to search from.-1
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.indexOf(null, 3, 0));
// => -1
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
int result = CollectionUtils.indexOf(collection, 3, 1);
System.out.println(result);
// => 2
}
}
Try in REPLCollectionUtils.initial(collection)
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to inspect.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.initial(null));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4);
List<Integer> result = CollectionUtils.initial(collection);
System.out.println(result);
// => [1, 2, 3]
}
}
Try in REPLCollectionUtils.intersection(collection, [values])
sourcemaven central repository
collection
of unique values that are included in all given collections
.1.0.2
collection
(Collections): The collection to inspect.[values]
(...Collections): The values to inspect.collection
of intersecting values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.intersection(null, Arrays.asList(1, 2, 3, 4)));
// => []
System.out.println(CollectionUtils.intersection(Arrays.asList(1, 2, 3, 4), null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, null);
List<Integer> collection2 = Arrays.asList(2, 3);
List<Integer> collection3 = Arrays.asList(2, 4, 5);
List<Integer> result = CollectionUtils.intersection(collection1, collection2, collection3);
System.out.println(result);
// => [2]
}
}
Try in REPLCollectionUtils.intersectionBy(collection, [predicate], [values])
sourcemaven central repository
collection
containing the elements that are present in all the provided collections
, based on the result of applying the predicate
function to generate the criterion for comparison.1.0.2
collection
(Collections): The collection to inspect.[predicate]
(Predicate): The function invoked per iteration.[values]
(...Collections): The collection to inspect.collection
of intersecting values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.intersectionBy(null, x -> x % 2 == 0, Arrays.asList(1, 2, 3, 4)));
// => []
System.out.println(CollectionUtils.intersectionBy(Arrays.asList(1, 2, 3, 4), x -> x % 2 == 0, null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3, 4);
List<Integer> collection2 = Arrays.asList(2, 3, 4, 5);
List<Integer> collection3 = Arrays.asList(3, 4, 6);
List<Integer> result = CollectionUtils.intersectionBy(collection1, x -> x % 2 == 0, collection2, collection3);
System.out.println(result);
// => [4]
}
}
Try in REPLCollectionUtils.intersectionWith(collection, [comparator], [values])
sourcemaven central repository
collections
using a custom comparator.1.0.2
collection
(Collections): The collection to inspect.[comparator]
(BiPredicate): The comparator invoked per element.[values]
(...Collections): The values to inspect.collection
of intersecting values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.intersectionWith(null, (a, b) -> a == b, Arrays.asList(1, 2, 3, 4)));
// => []
System.out.println(CollectionUtils.intersectionWith(Arrays.asList(1, 2, 3, 4), (a, b) -> a == b, null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3, 4);
List<Integer> collection2 = Arrays.asList(2, 3, 4, 5);
List<Integer> collection3 = Arrays.asList(3, 4, 6);
List<Integer> result = CollectionUtils.intersectionWith(collection1, Objects::equals, collection2, collection3);
System.out.println(result);
// => [3, 4]
}
}
Try in REPLCollectionUtils.join(collection, [separator=','])
sourcemaven central repository
collection
into a string separated by separator
.1.0.2
collection
(Collections): The collection to inspect.[separator]
(String): The element separator.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.join(null, ","));
// => ""
List<String> collection1 = Arrays.asList("apple", "banana", "cherry");
System.out.println(CollectionUtils.join(collection1, null));
// => "apple,banana,cherry"
List<Integer> collection2 = Arrays.asList(1, 2, 3);
System.out.println(CollectionUtils.join(collection2, "-"));
// => "1-2-3"
List<String> collection = Arrays.asList("apple", "banana", "cherry");
String result = CollectionUtils.join(collection, ", ");
System.out.println(result);
// => "apple, banana, cherry"
}
}
Try in REPLCollectionUtils.last(collection)
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to inspect.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.last(null));
// => Optional.empty();
List<Integer> collection = Arrays.asList(1, 2, 3);
Optional<Integer> result = CollectionUtils.last(collection);
System.out.println(result);
// => Optional[3]
}
}
Try in REPLCollectionUtils.lastIndexOf(collection, value)
sourcemaven central repository
collection
, searching from right to left.1.0.2
collection
(Collections): The collection to inspect.[value]
(<T>): The value to search for.-1
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.lastIndexOf(null, 2));
// => -1
List<Integer> collection = Arrays.asList(1, 2, 3, 2);
int result = CollectionUtils.lastIndexOf(collection, 2);
System.out.println(result);
// => 3
}
}
Try in REPLCollectionUtils.lastIndexOf(collection, value, [fromIndex])
sourcemaven central repository
collection
, searching from right to left.1.0.2
collection
(Collections): The collection to inspect.[value]
(<T>): The value to search for.[fromIndex]
(int): The index to search from.-1
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.lastIndexOf(null, 2, 3));
// => -1
List<Integer> collection = Arrays.asList(1, 2, 3, 2);
int result = CollectionUtils.lastIndexOf(collection, 2, 3);
System.out.println(result);
// => 3
}
}
Try in REPLCollectionUtils.nth(collection, [n])
sourcemaven central repository
collection
. If n is negative, the nth element from the end is returned.1.0.2
collection
(Collections): The collection to query.[n]
(int): The index of the element to return.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.nth(null, 1));
// => Optional.empty();
List<String> collection1 = Arrays.asList("apple", null, "cherry");
System.out.println(CollectionUtils.nth(collection1, 1));
// => Optional.empty();
List<String> collection2 = Arrays.asList("apple", "banana", "cherry");
Optional<String> result = CollectionUtils.nth(collection2, 1);
System.out.println(result);
// => Optional[banana]
}
}
Try in REPLCollectionUtils.pull(collection, [values])
sourcemaven central repository
collection
that are present in the specified values.1.0.2
collection
(Collections): The collection to modify.[values]
(...Collections): The values to remove.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> collection = Arrays.asList("apple", "banana", "cherry");
CollectionUtils.pull(collection, "banana", "cherry");
System.out.println(collection);
// => collection = ["apple"]
}
}
Try in REPLCollectionUtils.pullAll(collection, values)
sourcemaven central repository
collection
that are present in any of the specified values.1.0.2
collection
(Collections): The collection to modify.[values]
(...Collections): The values to remove.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> collection = Arrays.asList("apple", "banana", "cherry");
CollectionUtils.pullAll(collection, Arrays.asList("banana", "cherry"));
System.out.println(collection);
// => collection = ["apple"]
}
}
Try in REPLCollectionUtils.pullAllBy(collection, values, [iteratee])
sourcemaven central repository
collection
based on the result of applying an iteratee function to each element and value.1.0.2
collection
(Collections): The collection to modify.[values]
(...Collections): The values to remove.[iteratee]
(Function): The iteratee invoked per element.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> collection = Arrays.asList("apple", "banana", "cherry");
CollectionUtils.pullAll(collection, Arrays.asList("banana", "cherry"));
System.out.println(collection);
// => collection = ["apple"]
}
}
Try in REPLCollectionUtils.pullAllWith(collection, values, [comparator])
sourcemaven central repository
collection
that match any element in the values collection based on the provided comparator.1.0.2
collection
(Collections): The collection to modify.[values]
(...Collections): The values to remove.[comparator]
(BiPredicate): The comparator invoked per element.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> collection = Arrays.asList("apple", "banana", "cherry");
CollectionUtils.pullAllWith(collection, Arrays.asList("banana", "cherry"), String::equalsIgnoreCase);
System.out.println(collection);
// => collection = ["apple"]
}
}
Try in REPLCollectionUtils.pullAt(collection, [indexes])
sourcemaven central repository
collection
at the specified indexes.1.0.2
collection
(Collections): The collection to modify.[indexes]
(List<Integer>): The indexes of elements to remove.collection
of removed elements.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.pullAt(null, Arrays.asList(1, 3)));
// => []
System.out.println(CollectionUtils.pullAt(Arrays.asList(1, 3), null));
// => []
List<String> collection = Arrays.asList("apple", "banana", "cherry", "date");
List<String> result = CollectionUtils.pullAt(collection, Arrays.asList(1, 3));
System.out.println(result);
// => result = ["banana", "date"]
}
}
Try in REPLCollectionUtils.remove(collection, [predicate])
sourcemaven central repository
collection
that match the given predicate
.1.0.2
collection
(Collections): The collection to modify.[predicate]
(Predicate): The function invoked per iteration.collection
of removed elements.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.remove(null, s -> ((String) s).startsWith("b")));
// => []
List<String> collection = Arrays.asList("apple", "banana", "cherry", "date");
List<String> result = CollectionUtils.remove(collection, s -> ((String) s).startsWith("b"));
System.out.println(result);
// => result = ["banana"]
}
}
Try in REPLCollectionUtils.reverse(collection)
sourcemaven central repository
collection
so that the first element becomes the last, the second element becomes the second to last, and so on.1.0.2
collection
(Collections): The collection to modify.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.reverse(null));
// => []
List<String> collection = Arrays.asList("apple", "banana", "cherry");
List<String> result = CollectionUtils.reverse(collection);
System.out.println(result);
// => ["cherry", "banana", "apple"]
}
}
Try in REPLCollectionUtils.slice(collection, [start])
sourcemaven central repository
collection
from the specified start index to the end.1.0.2
collection
(Collections): The collection to slice.[start]
(int): The start position.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.slice(null, 1));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.slice(collection, 1);
System.out.println(result);
// => [2, 3, 4, 5]
}
}
Try in REPLCollectionUtils.slice(collection, [start], [end])
sourcemaven central repository
collection
from the specified start index to the end.1.0.2
collection
(Collections): The collection to slice.[start]
(int): The start position.[end]
(int): The end position.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.slice(null, 1, 4));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.slice(collection, 1, 4);
System.out.println(result);
// => [2, 3, 4]
}
}
Try in REPLCollectionUtils.tail(collection)
sourcemaven central repository
collection
.1.0.2
collection
(Collections): The collection to query.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.tail(null));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.tail(collection);
System.out.println(result);
// => result = [2, 3, 4, 5]
}
}
Try in REPLCollectionUtils.take(collection, [n])
sourcemaven central repository
collection
with n elements taken from the beginning.1.0.2
collection
(Collections): The collection to query.[n]
(int): The number of elements to take.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.take(null, 3));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.take(collection, 3);
System.out.println(result);
// => [1, 2, 3]
}
}
Try in REPLCollectionUtils.takeRight(collection, [n])
sourcemaven central repository
collection
with n elements taken from the end.1.0.2
collection
(Collections): The collection to query.[n]
(int): The number of elements to take.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.takeRight(null, 3));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.takeRight(collection, 3);
System.out.println(result);
// => [3, 4, 5]
}
}
Try in REPLCollectionUtils.takeRightWhile(collection, [predicate])
sourcemaven central repository
collection
with elements taken from the end. Elements are taken until predicate
returns falsey
.1.0.2
collection
(Collections): The collection to query.[predicate]
(Predicate): The function invoked per iteration.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.takeRightWhile(null, (Integer num) -> num.compareTo(2) < 0));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.takeRightWhile(collection, (Integer num) -> num.compareTo(2) > 0);
System.out.println(result);
// => [3, 4, 5]
}
}
Try in REPLCollectionUtils.takeWhile(collection, [predicate])
sourcemaven central repository
collection
with elements taken from the beginning. Elements are taken until predicate
returns falsey
.1.0.2
collection
(Collections): The collection to query.[predicate]
(Predicate): The function invoked per iteration.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.takeWhile(null, (Integer num) -> num.compareTo(2) < 0));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.takeWhile(collection, (Integer num) -> num.compareTo(4) < 0);
System.out.println(result);
// => [1, 2, 3]
}
}
Try in REPLCollectionUtils.union([collection])
sourcemaven central repository
1.0.2
collection
(...Collections): The collection to inspect.collection
of combined values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.union(null));
// => []
System.out.println(CollectionUtils.union(null, Arrays.asList(1, 2, 3)));
// => [1, 2, 3]
List<Integer> collection1 = Arrays.asList(1, 2, 3);
List<Integer> collection2 = Arrays.asList(3, 4, 5);
List<Integer> result = CollectionUtils.union(collection1, collection2);
System.out.println(result);
// => [1, 2, 3, 4, 5]
}
}
Try in REPLCollectionUtils.unionBy([iteratee], [collection])
sourcemaven central repository
collections
into a single collection
, applying a function to each element to determine its uniqueness and removing duplicates.1.0.2
[iteratee]
(Function): The iteratee invoked per element.collection
(...Collections): The collection to inspect.collection
of combined values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.unionBy(s -> ((String) s).length(), null));
// => []
System.out.println(CollectionUtils.unionBy(s -> ((String) s).length(), null, Arrays.asList("apple", "banana")));
// => [1, 2, 3]
List<String> list1 = Arrays.asList("apple", "banana");
List<String> list2 = Arrays.asList("cherry", "date");
List<String> result = CollectionUtils.unionBy(String::length, list1, list2);
System.out.println(result);
// => ["apple", "banana", "date"]
}
}
Try in REPLCollectionUtils.unionWith([comparator], [collection])
sourcemaven central repository
collections
into a single collection
, using a comparator to determine the uniqueness of elements, removing duplicates based on the comparison.1.0.2
comparator
(BiPredicate): The comparator invoked per element.collection
(...Collections): The collection to inspect.collection
of combined values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.unionBy(s -> ((String) s).length(), null));
// => []
System.out.println(CollectionUtils.unionBy(s -> ((String) s).length(), null, Arrays.asList("apple", "banana")));
// => [1, 2, 3]
List<String> list1 = Arrays.asList("apple", "banana");
List<String> list2 = Arrays.asList("cherry", "date");
List<String> result = CollectionUtils.unionBy(String::length, list1, list2);
System.out.println(result);
// => ["apple", "banana", "date"]
}
}
Try in REPLCollectionUtils.uniq(collection)
sourcemaven central repository
collection
with unique elements, removing duplicates.1.0.2
collection
(Collections): The collection to inspect.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.uniq(null));
// => []
List<Integer> collection = Arrays.asList(1, 2, 2, 3, 3, 3);
List<Integer> result = CollectionUtils.uniq(collection);
System.out.println(result);
// => [1, 2, 3]
}
}
Try in REPLCollectionUtils.uniqBy(collection, [iteratee])
sourcemaven central repository
collection
with unique elements based on a specific criterion, removing duplicates.1.0.2
collection
(Collections): The collection to inspect.[iteratee]
(Function): The iteratee invoked per element.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.uniqBy(null, value -> value));
// => []
List<String> collection = Arrays.asList(
"apple", "banana", "apple", "cherry", "banana"
);
List<String> result = CollectionUtils.uniqBy(collection, s -> s);
System.out.println(result);
// => ["apple", "banana", "cherry"]
}
}
Try in REPLCollectionUtils.uniqWith(collection, [comparator])
sourcemaven central repository
collection
with unique elements based on a specific criterion, removing duplicates.1.0.2
collection
(Collections): The collection to inspect.[comparator]
(BiPredicate): The comparator invoked per element.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.uniqWith(null, Integer::equals));
// => []
List<Integer> collection = Arrays.asList(1, 2, 2, 3, 3, 3);
List<Integer> result = CollectionUtils.uniqWith(collection, (a, b) -> a.equals(b));
System.out.println(result);
// => [1, 2, 3]
}
}
Try in REPLCollectionUtils.unzip(collection)
sourcemaven central repository
collection
of collections
into a list of lists by grouping elements at the same index.1.0.2
collection
(Collections): The collection of grouped elements to process.collection
of regrouped elements.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.unzip(null));
// => []
List<List<Integer>> grouped = Arrays.asList(
Arrays.asList(1, 2, 3),
Arrays.asList(4, 5, 6),
Arrays.asList(7, 8, 9)
);
List<List<Integer>> result = CollectionUtils.unzip(grouped);
System.out.println(result);
// => [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
}
}
Try in REPLCollectionUtils.unzipWith(collection, [iteratee])
sourcemaven central repository
collection
of collections
into a list of lists, and applies a combine function to each list of unzipped elements.1.0.2
collection
(Collection<? extends Collection<? extends T>>): The collection of grouped elements to process.[iteratee]
(Function<List<T>, T>): The function to combine regrouped values.collection
of regrouped elements.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.unzipWith(Collections.emptyList(), group ->
group.stream().mapToInt(num -> ((Integer) num).intValue()).sum()));
// => []
List<List<Integer>> grouped = Arrays.asList(
Arrays.asList(1, 2, 3),
Arrays.asList(4, 5, 6),
Arrays.asList(7, 8, 9)
);
List<Integer> result = CollectionUtils.unzipWith(grouped, group ->
group.stream().mapToInt(num -> ((Integer) num).intValue()).sum());
System.out.println(result);
// => [12, 15, 18]
}
}
Try in REPLCollectionUtils.without(collection, [values])
sourcemaven central repository
collection
excluding all given values.1.0.2
collection
(Collections): The collection to inspect.[values]
(...T): The values to exclude.collection
of filtered values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.without(null));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.without(collection, 2, 4);
System.out.println(result);
// => [1, 3, 5]
}
}
Try in REPLCollectionUtils.xor([collections])
sourcemaven central repository
collection
of unique values that is the symmetric difference of the given collections
.1.0.2
[collection]
(Collections): The collection to inspect.collection
of filtered values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.xor(null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3);
List<Integer> collection2 = Arrays.asList(3, 4, 5);
List<Integer> result = CollectionUtils.xor(collection1, collection2);
System.out.println(result);
// => [1, 2, 4, 5]
}
}
Try in REPLCollectionUtils.xorBy([iteratee], [collections])
sourcemaven central repository
1.0.2
[iteratee]
(Function): The iteratee invoked per element.[collection]
(...Collections): The collection to inspect.collection
of filtered values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.xorBy(Integer::doubleValue, null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3);
List<Integer> collection2 = Arrays.asList(3, 4, 5);
List<Integer> result = CollectionUtils.xorBy(Integer::doubleValue, collection1, collection2);
System.out.println(result);
// => [1, 2, 4, 5]
}
}
Try in REPLCollectionUtils.xorWith([comparator], [collections])
sourcemaven central repository
1.0.2
[comparator]
(BiPredicate): The comparator invoked per element.[collection]
(...Collections): The collection to inspect.collection
of filtered values.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.xorWith(Integer::equals, null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3);
List<Integer> collection2 = Arrays.asList(3, 4, 5);
List<Integer> result = CollectionUtils.xorWith((a, b) -> a.equals(b), collection1, collection2);
System.out.println(result);
// => [1, 2, 4, 5]
}
}
Try in REPLCollectionUtils.zip([collections])
sourcemaven central repository
1.0.2
[collection]
(...Collections): The collection to process.collection
of grouped elements.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.zip(null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3);
List<Integer> collection2 = Arrays.asList(4, 5, 6, 7);
List<List<Integer>> result = CollectionUtils.zip(collection1, collection2);
System.out.println(result);
// => [[1, 4], [2, 5], [3, 6], [null, 7]]
}
}
Try in REPLCollectionUtils.zipWith([iteratee], [collections])
sourcemaven central repository
1.0.2
[iteratee]
(Function<List<T>, R>): The function to combine grouped values.[collection]
(...Collections): The collection to process.collection
of grouped elements.import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Function<List<Integer>, String> iteratee = group -> group.stream().map(String::valueOf).collect(Collectors.joining("-"));
System.out.println(CollectionUtils.zipWith(iteratee, null));
// => []
List<Integer> collection1 = Arrays.asList(1, 2, 3);
List<Integer> collection2 = Arrays.asList(4, 5, 6);
List<String> result = CollectionUtils.zipWith(iteratee, collection1, collection2);
System.out.println(result);
// => ["1-4", "2-5", "3-6"]
}
}
Try in REPLCollectionUtils.zipObject([props], [values])
sourcemaven central repository
null
is used for missing values.1.0.2
[props]
(Collections): The property identifiers.[values]
(Collections): The property values.map
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> keys = Arrays.asList("a", "b", "c");
List<Integer> values = Arrays.asList(1, 2);
Map<String, Integer> result = CollectionUtils.zipObject(keys, values);
System.out.println(result);
// => {"a": 1, "b": 2, "c": null}
}
}
Try in REPLCollectionUtils.countBy(collection, [iteratee])
sourcemaven central repository
1.0.2
[props]
(Collections): The collection to iterate over.[iteratee]
(Function<? super T, ? extends K>): The iteratee to transform keys.map
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> collection = Arrays.asList("apple", "banana", "apple", "apple", "orange");
Map<String, Long> result = CollectionUtils.countBy(collection, String::toUpperCase);
System.out.println(result);
// => {"APPLE": 3, "BANANA": 1, "ORANGE": 1}
}
}
Try in REPLCollectionUtils.every(collection, [predicate])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to iterate over.[predicate]
(Predicate): The function invoked per iteration.true
if all elements pass the predicate check, else false
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.every(null, (Integer num) -> num.compareTo(3) < 0));
// => false
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
boolean result = CollectionUtils.every(numbers, (Integer num) -> num.compareTo(0) > 0);
System.out.println(result);
// => true
}
}
Try in REPLCollectionUtils.every(map, [biPredicate])
sourcemaven central repository
1.0.2
[map]
(Map<K, V>): The map to iterate over.[biPredicate]
(BiPredicate): The biPredicate to apply to each entry (key, value).true
if all elements pass the predicate check, else false
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.every(null, (Integer num) -> num.compareTo(3) < 0));
// => false
Map<String, Integer> map = new HashMap<>();
map.put("a", 1);
map.put("b", 2);
map.put("c", 3);
boolean result = CollectionUtils.every(map.values(), value -> value > 0);
System.out.println(result);
// => true
}
}
Try in REPLCollectionUtils.filter(collection, [predicate])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to iterate over.[predicate]
(Predicate): The function invoked per iteration.collection
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.filter(null, (Integer x) -> x % 2 == 0));
// => []
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.filter(list, (Integer x) -> x % 2 == 0);
System.out.println(result);
// => [2, 4]
}
}
Try in REPLCollectionUtils.filter(map, [predicate])
sourcemaven central repository
1.0.2
[map]
(Map<K, V>): The map to iterate over.[predicate]
(Predicate): The function invoked per iteration.Map
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Map<String, Integer> map = Map.of("a", 1, "b", 2, "c", 3);
Map<String, Integer> result = CollectionUtils.filter(map, (key, value) -> value > 1);
System.out.println(result);
// => {b=2, c=3}
}
}
Try in REPLCollectionUtils.find(collection, [predicate])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[predicate]
(Predicate): The function invoked per iteration.Optional.empty()
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.find(null, (String s) -> s.startsWith("b")));
// => Optional.empty();
List<String> collection = Arrays.asList("apple", "banana", "cherry");
Optional<String> result = CollectionUtils.find(collection, (String s) -> s.startsWith("b"));
System.out.println(result);
// => Optional[banana]
}
}
Try in REPLCollectionUtils.findLast(collection, [predicate])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[predicate]
(Predicate): The function invoked per iteration.Optional.empty()
.import java.util.*;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.findLast(null, (String s) -> s.startsWith("b")));
// => Optional.empty();
List<String> collection = Arrays.asList("apple", "banana", "cherry");
Optional<String> result = CollectionUtils.findLast(collection, (String s) -> s.startsWith("b"));
System.out.println(result);
// => Optional[banana]
}
}
Try in REPLCollectionUtils.flatMap(collection, [iteratee])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[iteratee]
(Function<? super T, ? extends Collection<? extends R>>): The function invoked per iteration.collection
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Function<Integer, Collection<String>> iteratee = num -> Arrays.asList("Item " + num);
System.out.println(CollectionUtils.flatMap(null, iteratee));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3);
List<String> result = CollectionUtils.flatMap(collection, iteratee);
System.out.println(result);
// => ["Item 1", "Item 2", "Item 3"]
}
}
Try in REPLCollectionUtils.flatMapDeep(collection, [iteratee])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[iteratee]
(Function<? super T, ? extends Collection<? extends R>>): The function invoked per iteration.collection
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Function<Integer, Collection<String>> iteratee = num -> Arrays.asList("Item " + num);
System.out.println(CollectionUtils.flatMapDeep(null, iteratee));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3);
List<Object> result = CollectionUtils.flatMapDeep(collection, iteratee);
System.out.println(result);
// => ["Item 1", "Item 2", "Item 3"]
}
}
Try in REPLCollectionUtils.flatMapDepth(collection, [iteratee], [depth])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[iteratee]
(Function<? super T, ? extends Collection<? extends R>>): The function invoked per iteration.[depth]
(int): The maximum recursion depth.collection
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Function<Integer, Collection<String>> iteratee = num -> Arrays.asList("Item " + num);
System.out.println(CollectionUtils.flatMapDepth(null, iteratee, 2));
// => []
List<Integer> collection = Arrays.asList(1, 2, 3);
List<Object> result = CollectionUtils.flatMapDepth(collection, iteratee, 2);
System.out.println(result);
// => ["Item 1", "Item 2", "Item 3"]
}
}
Try in REPLCollectionUtils.forEach(collection, [iteratee])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[iteratee]
(Consumer<? super T>): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<Integer> collection = Arrays.asList(1, 2, 3);
CollectionUtils.forEach(collection, num -> System.out.println("Element: " + num));
// => Element: 1
// => Element: 2
// => Element: 3
}
}
Try in REPLCollectionUtils.forEach(map, [iteratee])
sourcemaven central repository
1.0.2
[map]
(Map): The map to inspect.[iteratee]
(BiConsumer<? super K, ? super V>): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Map<String, Integer> map = Map.of("a", 1, "b", 2);
CollectionUtils.forEach(map, (key, value) -> System.out.println(key + " = " + value));
// => a = 1
// => b = 2
}
}
Try in REPLCollectionUtils.forEachRight(collection, [iteratee])
sourcemaven central repository
1.0.2
[collection]
(Collections): The collection to inspect.[iteratee]
(Consumer<? super T>): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<Integer> collection = Arrays.asList(1, 2, 3);
CollectionUtils.forEachRight(collection, num -> System.out.println("Element: " + num));
// => Element: 3
// => Element: 2
// => Element: 1
}
}
Try in REPLCollectionUtils.forEachRight(map, [iteratee])
sourcemaven central repository
1.0.2
[map]
(Map): The map to inspect.[iteratee]
(BiConsumer<? super K, ? super V>): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
Map<String, Integer> map = Map.of("a", 1, "b", 2);
CollectionUtils.forEachRight(map, (key, value) -> System.out.println(key + " = " + value));
// => b = 2
// => a = 1
}
}
Try in REPLCollectionUtils.groupBy(collection, [iteratee])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.[iteratee]
(Function<? super T, ? extends K>): The iteratee to transform keys.map
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
List<String> words = Arrays.asList("apple", "banana", "apricot", "blueberry");
Map<Character, List<String>> grouped = CollectionUtils.groupBy(words, word -> word.charAt(0));
System.out.println(grouped);
// => {a=[apple, apricot], b=[banana, blueberry]}
}
}
Try in REPLCollectionUtils.includes(collection, value)
sourcemaven central repository
1.0.2
collection
(Collection): The collection to inspect.value
(T): The value to search for.true
if value is found, else false
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
CollectionUtils.includes(null, "banana");
// result = false
List<String> words = Arrays.asList("apple", "banana", "apricot");
boolean result = CollectionUtils.includes(words, "banana");
System.out.println(result);
// result = true
}
}
Try in REPLCollectionUtils.keyBy(collection, [iteratee])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.iteratee
(Function<T, R>): The iteratee to transform keys.map
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.keyBy(null, String::length));
// Collections.emptyMap();
List<String> words = Arrays.asList("apple", "banana", "apricot");
Map<Integer, String> result = CollectionUtils.keyBy(words, String::length);
System.out.println(result);
// result = {5=apple, 6=banana, 7=apricot}
}
}
Try in REPLCollectionUtils.map(collection, [iteratee])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.iteratee
(Function<T, R>): The iteratee to transform keys.collection
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.map(null, String::length));
// => []
List<String> words = Arrays.asList("apple", "banana", "apricot");
List<Integer> result = CollectionUtils.map(words, String::length);
System.out.println(result);
// result = [5, 6, 7]
}
}
Try in REPLCollectionUtils.orderBy(collection, [comparator])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.comparator
(Comparator<? super T>): The comparator to sort by.collection
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.orderBy(null, Integer::compareTo));
// => []
List<Integer> numbers = Arrays.asList(5, 2, 8, 3);
List<Integer> result = CollectionUtils.orderBy(numbers, Integer::compareTo);
System.out.println(result);
// result = [2, 3, 5, 8]
}
}
Try in REPLCollectionUtils.partition(collection, [predicate])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.predicate
(Predicate): The function invoked per iteration.collection
of grouped elements.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.partition(null, (Integer n) -> n % 2 == 0));
// => []
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<List<Integer>> result = CollectionUtils.partition(numbers, (Integer n) -> n % 2 == 0);
System.out.println(result);
// result = [[2, 4], [1, 3, 5]]
}
}
Try in REPLCollectionUtils.reduce(collection, [identity], [accumulator])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.[identity]
(T): The initial value.[accumulator]
(BinaryOperator): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.reduce(null, 0, Integer::sum));
// => 0
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int result = CollectionUtils.reduce(numbers, 0, Integer::sum);
System.out.println(result);
// result = 15
}
}
Try in REPLCollectionUtils.reduce(collection, [accumulator])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.[accumulator]
(BinaryOperator): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.reduce(null, Integer::sum));
// => Optional.empty();
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
Optional<Integer> result = CollectionUtils.reduce(numbers, Integer::sum);
System.out.println(result);
// result = Optional[15]
}
}
Try in REPLCollectionUtils.reduceRight(collection, [identity], [accumulator])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.[identity]
(T): The initial value.[accumulator]
(BinaryOperator): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.reduceRight(null, 0, Integer::sum));
// => 0
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int result = CollectionUtils.reduceRight(numbers, 0, Integer::sum);
System.out.println(result);
// result = 15
}
}
Try in REPLCollectionUtils.reduceRight(collection, [accumulator])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.[accumulator]
(BinaryOperator): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.reduceRight(null, Integer::sum));
// => Optional.empty();
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
Optional<Integer> result = CollectionUtils.reduceRight(numbers, Integer::sum);
System.out.println(result);
// result = Optional[15]
}
}
Try in REPLCollectionUtils.reject(collection, [predicate])
sourcemaven central repository
not
satisfy the given predicate.1.0.2
collection
(Collection): The collection to iterate over.[predicate]
(Predicate): The function invoked per iteration.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.reject(null, (Integer n) -> n % 2 == 0));
// => [];
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.reject(numbers, (Integer n) -> n % 2 == 0);
System.out.println(result);
// result = [1, 3, 5]
}
}
Try in REPLCollectionUtils.sample(collection)
sourcemaven central repository
1.0.2
collection
(Collection): The collection to sample.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.sample(null));
// => Optional.empty();
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
Optional<Integer> result = CollectionUtils.sample(numbers);
System.out.println(result);
// result = A random element from the list (e.g., 3)
}
}
Try in REPLCollectionUtils.sampleSize(collection, [n])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to sample.[n]
(int): The number of elements to sample.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.sampleSize(null, 3));
// => [];
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.sampleSize(numbers, 3);
System.out.println(result);
// result = A random list of 3 elements, e.g., [2, 5, 1]
}
}
Try in REPLCollectionUtils.shuffle(collection)
sourcemaven central repository
1.0.2
collection
(Collection): The collection to shuffle.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.sampleSize(null, 3));
// => [];
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = CollectionUtils.shuffle(numbers);
System.out.println(result);
// result = A randomly shuffled list, e.g., [3, 1, 4, 2, 5]
}
}
Try in REPLCollectionUtils.size(collection)
sourcemaven central repository
1.0.2
collection
(Collection): The collection to inspect.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.size(null));
// => 0;
System.out.println(CollectionUtils.size(Arrays.asList(1, 2, 3, 4)));
// => 4;
System.out.println(CollectionUtils.size("Hello"));
// result = 5
}
}
Try in REPLCollectionUtils.some(collection, [predicate])
sourcemaven central repository
1.0.2
collection
(Collection): The collection to iterate over.[predicate]
(Predicate): The function invoked per iteration.true
if any element passes the predicate check, else false
.import java.util.*;
import java.util.function.Function;
import io.javadash.CollectionUtils;
public class Main {
public static void main(String[] args) {
System.out.println(CollectionUtils.some(null, (Integer num) -> num % 2 == 0));
// => false
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
boolean result = CollectionUtils.some(numbers, num -> num % 2 == 0);
System.out.println(result);
// result = true
}
}
Try in REPL“DateUtils” Methods
DateUtils.now()
sourcemaven central repository
System.currentTimeMillis()
.1.0.2
import java.util.*;
import io.javadash.DateUtils;
public class Main {
public static void main(String[] args) {
long currentTime = DateUtils.now();
System.out.println("Current time in milliseconds: " + currentTime);
}
}
Try in REPL“FunctionUtils” Methods
FunctionUtils.after([n], [func])
sourcemaven central repository
Consumer
that runs the provided Runnable
after being called a specified number of times. The Runnable
will be executed when the accept
method is invoked n
times.1.0.2
[n]
(int): The number of times the <code>accept</code> method needs to be called before the <code>Runnable</code> is executed.[func]
(Runnable): The <code>Runnable</code> to execute after the specified number of calls.Consumer
that tracks the number of calls and executes the Runnable
when the threshold is reached.import java.util.*;
import io.javadash.FunctionUtils;
public class Main {
public static void main(String[] args) {
Consumer<Void> consumer = FunctionUtils.after(3, () -> System.out.println("Executed"));
consumer.accept(null); // Nothing happens
}
}
Try in REPL“LangUtils” Methods
LangUtils.isEmpty([value])
sourcemaven central repository
Strings
, Collections
, Maps
, and Arrays
, and returns true
if the value is empty, null
, or has no elements.1.0.2
[value]
(Object): The value to check for emptiness.true
if value is empty, else false
.import java.util.*;
import io.javadash.LangUtils;
public class Main {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList();
boolean result = LangUtils.isEmpty(numbers);
System.out.println(result);
// Output: true
}
}
Try in REPL“StringUtils” Methods
StringUtils.includes(str, value)
sourcemaven central repository
1.0.2
str
(String): The string to search within.value
(String): The value to search for in the string.true
if the string contains the specified value; otherwise false
.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String sentence = "Hello, world!";
boolean result = StringUtils.includes(sentence, "world");
System.out.println(result);
// Output: true
}
}
Try in REPLStringUtils.camelCase(str)
sourcemaven central repository
1.0.2
str
(String): The string to convert to camelCase.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String sentence = "hello world example";
String result = StringUtils.camelCase(sentence);
System.out.println(result);
// Output: helloWorldExample
}
}
Try in REPLStringUtils.capitalize(str)
sourcemaven central repository
1.0.2
str
(String): The string to capitalize.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String word = "hello";
String result = StringUtils.capitalize(word);
System.out.println(result);
// Output: Hello
}
}
Try in REPLStringUtils.deburr(str)
sourcemaven central repository
1.0.2
str
(String): The string to deburr.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String word = "résumé";
String result = StringUtils.deburr(word);
System.out.println(result);
// Output: resume
}
}
Try in REPLStringUtils.endsWith(str, target)
sourcemaven central repository
string
ends with the given target string.1.0.2
str
(String): The string to inspect.target
(String): The string to search for.true
if string ends with target, else false
.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String sentence = "Hello, world!";
boolean result = StringUtils.endsWith(sentence, "world!");
System.out.println(result);
// Output: true
}
}
Try in REPLStringUtils.escape(str)
sourcemaven central repository
string
to their corresponding HTML entities.1.0.2
str
(String): The string to escape.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String rawString = "Hello & welcome!";
String result = StringUtils.escape(rawString);
System.out.println(result);
// Output: "Hello & welcome!"
}
}
Try in REPLStringUtils.escapeRegExp(str)
sourcemaven central repository
string
.1.0.2
str
(String): The string to escape.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String rawString = "Hello (world)!";
String result = StringUtils.escapeRegExp(rawString);
System.out.println(result);
// Output: "Hello \\(world\\)!"
}
}
Try in REPLStringUtils.kebabCase(str)
sourcemaven central repository
1.0.2
str
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String input = "HelloWorld Example";
String result = StringUtils.kebabCase(input);
System.out.println(result);
// Output: "hello-world-example"
}
}
Try in REPLStringUtils.lowerCase(str)
sourcemaven central repository
1.0.2
str
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String input = "Hello World Example";
String result = StringUtils.lowerCase(input);
System.out.println(result);
// Output: "hello world example"
}
}
Try in REPLStringUtils.lowerFirst(str)
sourcemaven central repository
1.0.2
str
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String input = "Hello";
String result = StringUtils.lowerFirst(input);
System.out.println(result);
// Output: "hello"
}
}
Try in REPLStringUtils.pad([str=''], [length=0], [chars=' '])
sourcemaven central repository
1.0.2
[str='']
(String): The string to pad.[length=0]
(int): The padding length.[chars=' ']
(String): The string used as padding.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.pad("hello", 10, "*");
System.out.println(result);
// Output: "**hello***"
}
}
Try in REPLStringUtils.padStart([str=''], [length=0], [chars=' '])
sourcemaven central repository
1.0.2
[str='']
(String): The string to pad.[length=0]
(int): The padding length.[chars=' ']
(String): The string used as padding.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.padStart("hello", 10, "*");
System.out.println(result);
// Output: "*****hello"
}
}
Try in REPLStringUtils.padEnd([str=''], [length=0], [chars=' '])
sourcemaven central repository
1.0.2
[str='']
(String): The string to pad.[length=0]
(int): The padding length.[chars=' ']
(String): The string used as padding.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.padEnd("hello", 10, "*");
System.out.println(result);
// Output: "hello*****"
}
}
Try in REPLStringUtils.repeat([string=''], [n])
sourcemaven central repository
1.0.2
[str='']
(String): The string to repeat.[n]
(int): The number of times to repeat the string.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.repeat("abc", 3);
System.out.println(result);
// Output: "abcabcabc"
}
}
Try in REPLStringUtils.replace([string=''], pattern, replacement)
sourcemaven central repository
1.0.2
[str='']
(String): The string to modify.[pattern]
(String): The pattern to replace.[replacement]
(String): The match replacement.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.replace("Hello World", "World", "Java");
System.out.println(result);
// Output: "Hello Java"
}
}
Try in REPLStringUtils.snakeCase([string=''])
sourcemaven central repository
1.0.2
[str='']
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.snakeCase("HelloWorld Example");
System.out.println(result);
// Output: "hello_world_example"
}
}
Try in REPLStringUtils.split([string=''], separator)
sourcemaven central repository
1.0.2
[str='']
(String): The string to split.separator
(String): The separator pattern to split by.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
List<String> result = StringUtils.split("apple,banana,orange", ",");
System.out.println(result);
// Output: ["apple", "banana", "orange"]
}
}
Try in REPLStringUtils.startCase([string=''])
sourcemaven central repository
1.0.2
[str='']
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.startCase("hello world!");
System.out.println(result);
// Output: "Hello World"
}
}
Try in REPLStringUtils.startsWith([string=''], [target])
sourcemaven central repository
1.0.2
[str='']
(String): The string to inspect.[target]
(String): The string to search for.true
if string starts with target, else false
.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
boolean result = StringUtils.startsWith("hello world", "hello");
System.out.println(result);
// Output: true
}
}
Try in REPLStringUtils.toLower([string=''])
sourcemaven central repository
1.0.2
[str='']
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String lowerValue = StringUtils.toLower("HELLO");
System.out.println(result);
// Output: hello
}
}
Try in REPLStringUtils.toUpper([string=''])
sourcemaven central repository
1.0.2
[str='']
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String upperValue = StringUtils.toUpper("hello");
System.out.println(result);
// Output: HELLO
}
}
Try in REPLStringUtils.trim([string=''], [chars=whitespace])
sourcemaven central repository
1.0.2
[str='']
(String): The string to trim.[chars=whitespace]
(String): The characters to trim.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.trim(" hello world ", " ");
System.out.println(result);
// Output: "hello world"
}
}
Try in REPLStringUtils.trimStart([string=''], [chars=whitespace])
sourcemaven central repository
1.0.2
[str='']
(String): The string to trim.[chars=whitespace]
(String): The characters to trim.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.trimStart(" hello world ", " ");
System.out.println(result);
// Output: "hello world "
}
}
Try in REPLStringUtils.trimEnd([string=''], [chars=whitespace])
sourcemaven central repository
1.0.2
[str='']
(String): The string to trim.[chars=whitespace]
(String): The characters to trim.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.trimEnd(" hello world ", " ");
System.out.println(result);
// Output: " hello world"
}
}
Try in REPLStringUtils.upperCase([string=''])
sourcemaven central repository
1.0.2
[str='']
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.upperCase("hello world 123");
System.out.println(result);
// Output: "HELLO WORLD 123"
}
}
Try in REPLStringUtils.upperFirst([string=''])
sourcemaven central repository
1.0.2
[str='']
(String): The string to convert.import java.util.*;
import io.javadash.StringUtils;
public class Main {
public static void main(String[] args) {
String result = StringUtils.upperFirst("hello");
System.out.println(result);
// Output: "Hello"
}
}
Try in REPL