how to change items in a list of string in java8

oshai

I want to change all items in list.
What is the correct way to do it with java8?

public class TestIt {

public static void main(String[] args) {
    ArrayList<String> l = new ArrayList<>();
    l.add("AB");
    l.add("A");
    l.add("AA");
    l.forEach(x -> x = "b" + x);
    System.out.println(l);
}

}
Alexis C.

You can use replaceAll.

Replaces each element of this list with the result of applying the operator to that element.

ArrayList<String> l = new ArrayList<>(Arrays.asList("AB","A","AA"));
l.replaceAll(x -> "b" + x);
System.out.println(l);

Output:

[bAB, bA, bAA]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change items position in List<string>

From Dev

How to group List<Map<String,Object>> to Map<String,List<Map<String,Object>> in Java8

From Dev

How do I merge two List of String into one List without duplicate in Java8 stream

From Dev

How to convert List<Object[]> to Map<String,BigInteger> with Streams & Lambda Java8

From Dev

How to get max value in List<Map<String, Object>> at Java8

From Dev

How to convert List<Object[]> to Map<String,BigInteger> with Streams & Lambda Java8

From Dev

How to do filter a list in Java8?

From Dev

How to change the default separator of my list items?

From Dev

How to dynamically change List items for the ListView in Android?

From Dev

How to change items in a tuple without casting to a list?

From Dev

how to change background color of specific list items

From Dev

How to dynamically change List items for the ListView in Android?

From Dev

Java8 convert List of Map to List of string

From Dev

How to select the finest granularity of string items in a list

From Java

How to concatenate items in a list to a single string?

From Dev

How to check if all items in list are string

From Dev

elixir : how to count number of list items in a string

From Dev

How to check if all items in list are string

From Dev

How change a list of array of strings to a list of string

From Dev

How to change following nested FOR loops into Java8 Stream API?

From Java

Java 8: How to convert List<String> to Map<String,List<String>>?

From Dev

Java 8: How to convert List<String> to Map<String,List<String>>?

From Dev

How to iterate a python list and compare items in a string or another list

From Dev

c# -How to put items from a List<string> to List<object>

From Java

How to add elements of a Java8 stream into an existing List

From Dev

How to effectively create list using if in java8?

From Dev

How to partition a list by predicate using java8?

From Dev

How do I sort a List of TreeSets with java8 streams

From Dev

Java8 : How to filter a map of List value via stream

Related Related

  1. 1

    Change items position in List<string>

  2. 2

    How to group List<Map<String,Object>> to Map<String,List<Map<String,Object>> in Java8

  3. 3

    How do I merge two List of String into one List without duplicate in Java8 stream

  4. 4

    How to convert List<Object[]> to Map<String,BigInteger> with Streams & Lambda Java8

  5. 5

    How to get max value in List<Map<String, Object>> at Java8

  6. 6

    How to convert List<Object[]> to Map<String,BigInteger> with Streams & Lambda Java8

  7. 7

    How to do filter a list in Java8?

  8. 8

    How to change the default separator of my list items?

  9. 9

    How to dynamically change List items for the ListView in Android?

  10. 10

    How to change items in a tuple without casting to a list?

  11. 11

    how to change background color of specific list items

  12. 12

    How to dynamically change List items for the ListView in Android?

  13. 13

    Java8 convert List of Map to List of string

  14. 14

    How to select the finest granularity of string items in a list

  15. 15

    How to concatenate items in a list to a single string?

  16. 16

    How to check if all items in list are string

  17. 17

    elixir : how to count number of list items in a string

  18. 18

    How to check if all items in list are string

  19. 19

    How change a list of array of strings to a list of string

  20. 20

    How to change following nested FOR loops into Java8 Stream API?

  21. 21

    Java 8: How to convert List<String> to Map<String,List<String>>?

  22. 22

    Java 8: How to convert List<String> to Map<String,List<String>>?

  23. 23

    How to iterate a python list and compare items in a string or another list

  24. 24

    c# -How to put items from a List<string> to List<object>

  25. 25

    How to add elements of a Java8 stream into an existing List

  26. 26

    How to effectively create list using if in java8?

  27. 27

    How to partition a list by predicate using java8?

  28. 28

    How do I sort a List of TreeSets with java8 streams

  29. 29

    Java8 : How to filter a map of List value via stream

HotTag

Archive