package lesson3;
import lesson2.Boat;
import lesson2.Car;
import lesson2.IWater;
import lesson2.RaceCar;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* User: gkislin
* Date: 14.04.2014
*/
public class Main {
public static final double PI = 3.1415;
public static void main(String[] args) {
sampleArray();
System.out.println();
sampleInstanceOf();
System.out.println();
sampleStringEquals();
System.out.println();
sampleMapKeysConcatenation();
System.out.println();
sampleInstanceOf();
System.out.println();
sampleBoxingProblem();
}
private static void sampleInstanceOf() {
Boat b1 = new Boat();
Car c1 = new Car();
System.out.println(c1 instanceof RaceCar);
System.out.println(c1.getClass().isInstance(b1));
System.out.println(IWater.class.isInstance(b1));
}
static void sampleStringEquals() {
String one = "123";
System.out.println("b123" == ("b" + one));
System.out.println("b123".equals("b" + one));
System.out.println(one.charAt(0));
}
static void sampleBoxingProblem() {
print(2);
print(null);
}
static int print(Integer o) {
System.out.println(o);
return o;
}
static void sampleArray() {
int[] arr1 = new int[]{1, 2, 3};
int[] arr2 = new int[3];
String[] arr3 = new String[]{"1", "2", "3"};
arr3[0] = "3";
System.out.println(Arrays.toString(arr3));
}
static void sampleMapKeysConcatenation() {
Map<String, Integer> map = new HashMap<>();
map.put("a1", 1);
map.put("a2", 2);
map.put("a3", 3);
map.put("a4", 4);
StringBuilder res = new StringBuilder();
for (String key : map.keySet()) {
res.append(key);
}
System.out.println(res.toString());
}
}