cmd输入javac 后输入的参数存在 String[] args中
- 当你使用命令行的形式运行.class文件时,向你的类传递参数.
- C:>java YourClassName 参数1 [参数2 参数3 …] 参数之间用一个空格作为间隔符.
- String[] args 这个字符串数组是保存运行main函数时输入的参数的,例如main函数所在的类名为test
- 那么你在cmd运行 java test a b c 时,args[0] = a ,args[1]=b, args[2]=c 你就可以在你的程序中调用你输入的这些变量了
重定向 I/O
- 要输入的放在 inof.txt里
- javac 文件名.java 编译
- java 文件名 < inof.txt 文件里的内容编程了程序的输入 重定向代替了Scanner
数组
多维数组初始化
a指向9个空的 分部创建数组
int[][] a = new int[9][];
for(int i = 0; i < a.length; i++)
a[i] = new int[i+1];
ArrayList removeIf
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.removeIf(s -> s%2==0); // 过滤掉模2等于0的数
list.forEach(s -> System.out.println(s)); // 输出 1 3
List<String> strings = new ArrayList<>();
strings.add("ab");
strings.add("ac");
strings.add("bc");
strings.add("cd");
Predicate<String> predicate = (s) -> s.startsWith("a"); // 这里单独定义了过滤器
strings.removeIf(predicate); // 过滤掉以"a"开头的元素
strings.forEach(s -> System.out.println(s)); // 输出 bc cd
}
---------------------
作者:HelloMrZheng
来源:优快云
原文:https://blog.csdn.net/HelloMrZheng/article/details/7014