List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
Iterator<Integer> it = list.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将按顺序迭代1到6.我们可以交替迭代相同的列表,以便在1, 3, 5不更改while循环的情况下进行打印吗?
情况1:
char c='A'+'A';
System.out.println(c); // print question mark (?)
Run Code Online (Sandbox Code Playgroud)
案例2:
char c1='A';
char c2='A'+c1; // Compile time error
System.out.println(c2);
Run Code Online (Sandbox Code Playgroud)
在case1中我有逻辑当我添加两个字符文字时,ascii值的总和是打印,这相当于问号的ascii值.但在case2中为什么编译时错误显示' 无法从int转换为char '
如果char + char = int则此规则必须适用于这两种情况.