Even if I develop it in Java, there are many places I use it without knowing it well.
int[] arrayInt = new int[2];
System.out.println(arrayInt .length); //2 is displayed
for (int i : arrayInt ) {
System.out.println(i); //0 is displayed
}
String[] arrayStr = new String[2];
System.out.println(arrayStr.length); //2 is displayed
for (String str : arrayStr) {
System.out.println(str); //null is displayed
}
int[] arrayInt = new int[2] { 1, 2 }; //Compile error
int[] array1 = new int[1];
int[] array2 = { 1, 2, 3 };
array1 = array2;
for (int i : array1) {
System.out.println(i); // 1, 2,Is displayed as 3
}
int[] array1 = { 1 };
int[] array2 = array1.clone();
array2[0] = 2;
System.out.println(array1[0]); //1 is displayed
System.out.println(array2[0]); //2 is displayed
StringBuilder sb = new StringBuilder(5);
String str = "";
System.out.println(sb.equals(str)); //False for reference comparison
System.out.println(sb.toString().equals(str)); //True for value comparison
interface A {
void test1(); //public is automatically attached
void test2(); //public is automatically attached
}
abstract class B implements A{
abstract void test3(); //public cannot be attached automatically
//Private qualification is not possible
}
class C extends B{
public void test1(){} //Compile error if not defined
public void test2(){} //Compile error if not defined
public void test3(){} //Compile error if not defined
}
public class test {
public static void main(String[] args) {
A a = new A(); //Compile error
B b = new B(); //Compile error
C c = new C();
}
}
public static void main(String[] args) {
test(1, 2);
}
private static void test(int... i) {
System.out.println("A");
}
private static void test(int i, int j) { //Called
System.out.println("B");
}
int i = 0;
do
System.out.println("A");
i++; //Compile error because multiple lines cannot be written in the abbreviated format
while (i < 3);
for (int i = 0, j = 0; i < 5; i++) {
System.out.println("A");
}
for (int i = 0, int j = 0; i < 5; i++) { //Compile error
System.out.println("A");
}
Recommended Posts