fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.stream.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. List<ProductMovement> pro = Arrays.asList(new ProductMovement(1, "unidade"),
  15. new ProductMovement(2, "caixa"),
  16. new ProductMovement(3, "unidade"),
  17. new ProductMovement(4, "caixa"));
  18.  
  19. List<ProductMovement> lista = filterFractionedMovements(pro);
  20. lista.forEach(element -> System.out.println(element.getId()));
  21. }
  22.  
  23. static List<ProductMovement> filterFractionedMovements(List<ProductMovement> reservMovements) {
  24. return (List<ProductMovement>) reservMovements.stream()
  25. .filter(px -> px.getNome().equals("unidade"))
  26. .collect(Collectors.toList());
  27. }
  28.  
  29. static class ProductMovement {
  30. private int id;
  31. private String nome;
  32.  
  33. public ProductMovement(int id, String nome) {
  34. this.id = id;
  35. this.nome = nome;
  36. }
  37.  
  38. public ProductMovement() {
  39. }
  40.  
  41. public int getId() {
  42. return id;
  43. }
  44.  
  45. public void setId(int id) {
  46. this.id = id;
  47. }
  48.  
  49. public String getNome() {
  50. return nome;
  51. }
  52.  
  53. public void setNome(String nome) {
  54. this.nome = nome;
  55. }
  56. }
  57. }
Success #stdin #stdout 0.07s 34268KB
stdin
Standard input is empty
stdout
1
3