Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From a List<String> to a Map<Label, PasswordField> using java 8

Is possibile to generate an HashMap using stream and collector? I've tried with something like:

 myList.stream()
.map(Label::new)
.collect(Collectors.toMap(Function.identity(), PasswordField::new))

but it obviusly doesn't work, I've tried other solution, but without success. Have you some advidce?

like image 915
Ross Avatar asked Jul 28 '26 06:07

Ross


1 Answers

The PasswordField class only has a default constructor which means PasswordField::new will not work as it's equivalent to (Label l) -> new PasswordField(l). instead the value mapper should be (Label l) -> new PasswordField() or simply l -> new PasswordField();

like image 115
Ousmane D. Avatar answered Jul 30 '26 08:07

Ousmane D.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!