Czy rozmiar ma znaczenie?
- Co pojawi się na ekranie po uruchomieniu poniższego kodu?
public class SizeDoesMatterVol2 {
public static void main(String[] args) {
final List<Integer> elements = Arrays.asList(1, 2, 3);
final List<Integer> listOfInts = new ArrayList<Integer>(elements);
final Collection<Integer> collectionOfInts = new ArrayList<Integer>(elements);
listOfInts.remove(0);
collectionOfInts.remove(0);
System.out.println(listOfInts.size() == collectionOfInts.size());
}
}
Czytaj więcej…
Czy rozmiar ma znaczenie?
- Co pojawi się na ekranie po uruchomieniu poniższego kodu?
public class SizeDoesMatterVol1 {
public static void main(String[] args) {
final List integers = Arrays.asList(new Integer[]{1, 2, 3});
final List ints = Arrays.asList(new int[]{1, 2, 3});
System.out.println(ints.size() == integers.size());
}
}
Czytaj więcej…
16 października, 2011
rafos
- Co pojawi się na ekranie po uruchomieniu poniższego kodu?
public class GenericEquality {
public static void main(String[] args) {
final Class clazz1 = new ArrayList<Integer>().getClass();
final Class clazz2 = new ArrayList<String>().getClass();
final boolean eq1 = (clazz1 == clazz2);
final boolean eq2 = clazz1.equals(clazz2);
System.out.println(eq1 + " " + eq2);
}
}
Czytaj więcej…
- Co pojawi się na ekranie po uruchomieniu poniższego kodu?
public class LovelyStrings {
public static void main(String[] args) {
String[] words = {"I ", "love ", "the ", "String ", "class!"};
String statement = null;
for (String word : words) {
statement += word;
}
System.out.println(statement);
}
}
Czytaj więcej…
- Co może pojawić się na ekranie po uruchomieniu poniższego kodu? Zakładamy, że program kompiluje i uruchamia się poprawnie.
public class Tricky {
public static void main(String[] args) {
try {
if (0 == args.length) {
throw new NullPointerException();
}
} catch (Throwable e) {
System.out.print("catch ");
doSomething();
} finally {
System.out.println("finally ");
}
}
}
Czytaj więcej…