Skip to main content
deleted 276 characters in body
Source Link
Craig P. Motlin
  • 26.7k
  • 18
  • 101
  • 126

If you use Eclipse Collections, there is indeed a third way to approach your specific example.you can use the Eclipse Collections' collectIf() method allows a single callmethod to deal with both filteringfilter and transformationtransform at the same time.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

EC's Collect pattern is documented in its reference guide.

Note: I am a committer for Eclipse Collections.

If you use Eclipse Collections, there is indeed a third way to approach your specific example. Eclipse Collections' collectIf() method allows a single call to deal with both filtering and transformation.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

EC's Collect pattern is documented in its reference guide.

Note: I am a committer for Eclipse Collections.

If you use Eclipse Collections, you can use the collectIf() method to filter and transform at the same time.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

Note: I am a committer for Eclipse Collections.

provide links and clarify this answers the example rather than the general question
Source Link

If you use Eclipse Collections you can use theEclipse Collections, there is indeed a third way to approach your specific example. collectIf() methodEclipse Collections' collectIf() method allows a single call to deal with both filtering and transformation.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a StreamStream.

EC's Collect pattern is documented in its reference guide.

Note: I am a committer for Eclipse Collections.

If you use Eclipse Collections you can use the collectIf() method.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

Note: I am a committer for Eclipse Collections.

If you use Eclipse Collections, there is indeed a third way to approach your specific example. Eclipse Collections' collectIf() method allows a single call to deal with both filtering and transformation.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

EC's Collect pattern is documented in its reference guide.

Note: I am a committer for Eclipse Collections.

deleted 167 characters in body
Source Link
Craig P. Motlin
  • 26.7k
  • 18
  • 101
  • 126

If you use Eclipse Collections you can use the collectIf() method.

MutableList<Integer> source =
    Lists.mutable.with(1, null, 2, null, 3, null, 4, null, 5);

MutableList<String> result = source.collectIf(Objects::nonNull, String::valueOf);

Assert.assertEquals(Lists.immutable.with("1", "2", "3", "4", "5"), result);
myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

Note: I am a committer for Eclipse Collections.

If you use Eclipse Collections you can use the collectIf() method.

MutableList<Integer> source =
    Lists.mutable.with(1, null, 2, null, 3, null, 4, null, 5);

MutableList<String> result = source.collectIf(Objects::nonNull, String::valueOf);

Assert.assertEquals(Lists.immutable.with("1", "2", "3", "4", "5"), result);

It evaluates eagerly and should be a bit faster than using a Stream.

Note: I am a committer for Eclipse Collections.

If you use Eclipse Collections you can use the collectIf() method.

myFinalList = myListToParse.collectIf(
    Objects::nonNull,
    elt -> doSomething(elt));

It evaluates eagerly and should be a bit faster than using a Stream.

Note: I am a committer for Eclipse Collections.

deleted 89 characters in body
Source Link
Donald Raab
  • 6.6k
  • 2
  • 36
  • 45
Loading
updated with project migration to Eclipse Foundation
Source Link
Donald Raab
  • 6.6k
  • 2
  • 36
  • 45
Loading
added 51 characters in body
Source Link
Craig P. Motlin
  • 26.7k
  • 18
  • 101
  • 126
Loading
Source Link
Craig P. Motlin
  • 26.7k
  • 18
  • 101
  • 126
Loading