-
-
Save kazuy/6699caa2c03d4d0a2c48ee431f0bba69 to your computer and use it in GitHub Desktop.
空行削除
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.function.UnaryOperator; | |
public class LambdaSample { | |
public static void main(String[] args) { | |
List<String> list = Arrays.asList("Tokyo", "Kanagawa", "Saitama", "Chiba", "Gunma", "Tochigi", "Ibaraki"); | |
// SE7以前の書き方 | |
before(list); | |
// SE8以降(ラムダ式)の書き方 | |
after(list); | |
} | |
private static void before(List<String> list) { | |
list.replaceAll(new UnaryOperator<String>() { | |
@Override | |
public String apply(String s) { | |
return s.toUpperCase(); | |
} | |
}); | |
System.out.println(list); | |
} | |
private static void after(List<String> list) { | |
list.replaceAll(s -> s.toUpperCase()); | |
System.out.println(list); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment