Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Commonmark migration
Source Link

##You need to use method references.

You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map, and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}

##You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map, and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}

You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map, and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

##You need to use method references. method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map, and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}

##You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map, and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}

##You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map, and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}
added 943 characters in body
Source Link
durron597
  • 32.5k
  • 18
  • 106
  • 164

##You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Just doInstead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map , and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}

You don't need a method, that's sort of the whole idea. Just do:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

##You need to use method references.

You don't need to create a method like operateListWith, that's sort of the whole idea. Instead, you can operate on each value using forEach by doing something like this:

listStuff.stream.forEach(object::methodToPassA);

For example:

public class StreamExample {
 public static void main(String[] args) {
 List<String> list = Arrays.asList("Hello", "What's Up?", "GoodBye");
 list.stream().forEach(System.out::println);
 }
}

Output:

Hello
What's Up?
GoodBye

In your case, you can get the value inside Stuff using .map , and then operate on it using forEach, like this:

public class DumbTest {
 public class Stuff {
 public String getA() {
 return "a";
 }
 public String getB() {
 return "b";
 }
 }
 public String methodToPassA(Stuff stuff) {
 return stuff.getA();
 }
 public String methodToPassB(Stuff stuff) {
 return stuff.getA();
 }
 public DumbTest() {
 List<Stuff> listStuff = Arrays.asList(new Stuff(), new Stuff());
 listStuff.stream()
 .map(this::methodToPassA)
 .forEach(System.out::println);
 }
 public static void main(String[] args) {
 DumbTest l = new DumbTest();
 }
}
Source Link
durron597
  • 32.5k
  • 18
  • 106
  • 164
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /