How to find all 3 letters words from a list in Java

1 Answer

0 votes
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.List;

public class Program {
    public static void main(String[] args) {
        List<String> lst = new ArrayList<>(List.of("python", "c", "c++", "c#", "java", "php", "nodejs", "ada"));

        List<String> threeLetter_words = lst.stream()
                                           .filter(word -> word.length() == 3)
                                           .collect(Collectors.toList());

        System.out.println(String.join(", ", threeLetter_words));
    }
}


  
  
/*
run:
  
c++, php, ada
  
*/

 



answered Jun 21, 2024 by avibootz

Related questions

1 answer 119 views
1 answer 143 views
1 answer 99 views
1 answer 103 views
1 answer 99 views
1 answer 113 views
...