BoostList - wuyichen24/boost GitHub Wiki

BoostList is based on ArrayList. But it provides you the different way to loop or manipulate the elements in a list, and also convert the list to map structure. For example, if you want to loop on each element in string list, the traditional way is

for (String str : stringList) {
    System.out.println(str);
}

But for BoostList, you can do it like:

stringBoostList.foreach(new VoidFunction<String>() {
    public void call(String str) {
       System.out.println(str);
    }
});

Methods for BoostList

filter

Return a new BoostList containing only the elements that satisfy a predicate.

map

Return a new BoostList by applying a function to all elements of this BoostList.

flatMap

Return a new BoostList by first applying a function to all elements of this BoostList, and then flattening the results.

BoostList<String> list = new BoostList<String>();
list.add("apple,tree,car,king");
list.add("open,door,window,run");
list.add("high,small,tall,computer,team");

BoostList<String> newList = list.flatMap(new FlatMapFunction<String, String>() {
	public Iterable<String> call(String s) { 
		return Arrays.asList(s.split(","));        // split one element into multiple elements
	}
});

So the new list will have: "apple", "tree", "car", "king", "open", "door", "window", "run", "high", "small", "tall", "computer", "team".

mapToPair

Return a new BoostMap by applying a transforming function to all elements of this BoostList.

distinct

Remove duplicates. This is based on equals() to identify the same elements.

union

Produce an BoostList containing elements from both.

intersection

Return a BoostList containing only elements found in both 2 BoostLists.

{1,2,3}.intersection({3,4,5}) = {3} 

subtract

Remove the contents of one BoostList.

{1,2,3}.subtract({3,4,5}) = {1,2}

cartesian

Return the Cartesian product (all ordered pairs) of 2 BoostLists.

{a,b,c}.cartesian({x,y,z}) = {(a,x),(a,y),(a,z),(b,x),(b,y),(b,z),(c,x),(c,y),(c,z)}

foreach

Applies a function to all elements of this BoostList. It is the alteration of for-loop.

collect

Convert a BoostList into a normal ArrayList.

count

Return the number of elements in the BoostList.

countByValue

Return the count of each unique value in this BoostList as a map of (value, count) pairs.

{a,d,a,b,b,e,r,e,a}.countByValue() = {(a,3),(b,1),(d,1),(e,2),(r,1)}

take

Take the first N elements of this BoostList.

⚠️ **GitHub.com Fallback** ⚠️