The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

dwschulze (36) [Avatar] Offline
#1
The code on the bottom of page 61 doesn't work. I don't see how it could work given that you don't pass any arguments for it to sort. Here's the code and the output:


List<String> str = Arrays.asList("a", "b", "A", "B");
System.out.println(str);
str.sort((s1,s2) -> s1.compareToIgnoreCase(s2)) ;
System.out.println(str);

List<String> str2 = Arrays.asList("a", "b", "A", "B");
System.out.println(str2);
str.sort(String::compareToIgnoreCase) ;
System.out.println(str2);


[a, b, A, B]
[a, A, b, B]
[a, b, A, B]
[a, b, A, B]
dwschulze (36) [Avatar] Offline
#2
Re: Using the method reference to String::compareToIgnoreCase doesn't sort
My bad. I had a typo on the second last line (str instead of str2).
raoul-gabriel.urma (37) [Avatar] Offline
#3
Re: Using the method reference to String::compareToIgnoreCase doesn't sort
Hi,

glad to hear all is good smilie I'll rename the variables in the book so it is clearer.

Thanks,
Raoul
dwschulze (36) [Avatar] Offline
#4
Re: Using the method reference to String::compareToIgnoreCase doesn't sort
It's my code that had the variable problem. Your code just shows how to use String:compareToIgnoreCase in a lambda.