0

I am new to Java streams, so I hope someone can debug this. I don't understand how I'm getting the lowest number.

public class main {

    public static void main(String[] args) {
        Product p1 = new Product("1", "name1", 1000);
        Product p2 = new Product("2", "name2", 2000);
        Product p3 = new Product("3", "name3", 3000);
        Product p4 = new Product("4", "name4", 4000);

        HashMap<String, Product> map = new  HashMap<String, Product>();

        map.put(p1.getId(), p1);
        map.put(p2.getId(), p2);
        map.put(p3.getId(), p3);
        map.put(p4.getId(), p4);


        int i = (Integer) map.values().stream()
                .map(x -> (Integer) Integer.valueOf(x.getId()))
                .max(Integer::max).get();

        System.out.println(i);
    }

}
Boann
  • 48,794
  • 16
  • 117
  • 146
Wrapper
  • 794
  • 10
  • 25

0 Answers0