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…
Kolejna zagadka, tym razem wzorowana na egzaminie SCJP.
- Co pojawi się na ekranie po uruchomieniu poniższego kodu?
import java.util.*;
public class WrappersAndBoxing {
private static String out = "";
public static void main(String[] args) {
int x = 4;
Boolean y = true;
short[] sa = {1, 2, 3};
String s = "";
go(x, y);
go((int) sa[2]);
go(sa[2]);
go(Arrays.asList(sa), s);
go(new ArrayList<Integer>(1));
go(1L / 0.0);
go(x);
go(sa, sa);
go(sa);
System.out.println(out);
}
static void go(Short[] ints1, short[] ints2) {
out += "1";
}
static void go(Object o) {
out += "2";
}
static void go(Integer... i) {
out += "3";
}
static void go(Long l) {
out += "4";
}
static void go(Object[] os, Object... o) {
out += "5";
}
static void go(Short h) {
out += "6";
}
static void go(Object... o) {
out += "7";
}
static void go(List<Number> l) {
out += "8";
}
}
Czytaj więcej…
Kategorie:Java Puzzle Tagi:ArrayList, Arrays, asList, boolean, int, integer, List, Long, number, Object, Short, String, varargs