Skip to main content
deleted 338 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a)   .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elemFunctions.sizeidentity()])); }   }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0'  

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a)   .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); }   }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0'  

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a) .transformAndConcat(Functions.identity()) .toList(); 
deleted 14 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160

Merging lists without loop with Guava

Using FluentIterable.transformAndConcatFluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a) .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); } }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0' 

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a) .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); } }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0' 

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a) .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); } }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0' 
deleted 9 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160

Solution without loop with Guava

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat and JDK 1FluentIterable.transformAndConcat.7 for simplicity

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

ImmutableList<String>List<String> combined = FluentIterable.from(a) .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); } }).toList(); System.out.println(combined.toString()); 

Result

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0'  

Solution without loop with Guava

Using FluentIterable.transformAndConcat and JDK 1.7 for simplicity

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

ImmutableList<String> combined = FluentIterable.from(a) .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); } }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Merging lists without loop with Guava

Using FluentIterable.transformAndConcat.

Applies function to each element of this fluent iterable and returns a fluent iterable with the concatenated combination of results. function returns an Iterable of results.

Usage

List<String> combined = FluentIterable.from(a) .transformAndConcat(new Function<List<String>, List<String>>() { @Override public List<String> apply(List<String> elem) { return Arrays.asList(elem.toArray(new String[elem.size()])); } }).toList(); System.out.println(combined.toString()); 

Result

[a, b, c, d, 1, 2, 3, 4] 

Dependency

'com.google.guava:guava:15.0'  
deleted 98 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160
Loading
added 202 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160
Loading
added 233 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160
Loading
added 352 characters in body
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160
Loading
Source Link
MariuszS
  • 31.8k
  • 13
  • 120
  • 160
Loading