import java.util.ArrayList;
import java.util.HashMap;
import sun.text.CompactShortArray.Iterator;
public class AddressTest {
public static class CallByValue{
public int a;
}
public static void CallByReference(CallByValue param){
param.a = 100;
}
public static void main(String[] args) {
// ---------------------------------- #case1----------------------------------------------
ArrayList<Integer> myArrayList1=new ArrayList<Integer>();
ArrayList<Integer> myArrayList2=new ArrayList<Integer>();
myArrayList1.add(10);
myArrayList1.add(20);
myArrayList1.add(30);
// myArrayList1 = 10,20,30
myArrayList2 = myArrayList1;
myArrayList2.add(40);
myArrayList2.add(0,5);
myArrayList1.add(50);
// myArrayList2 = 5,10,20,30,40
System.out.println("myArrayList1값: "+myArrayList1); // 5,10,20,30,40
System.out.println("myArrayList2값: "+myArrayList2); // 5,10,20,30,40
// ---------------------------------- #case2----------------------------------------------
HashMap<Integer, String> myHashMap1 = new HashMap<Integer, String>();
HashMap<Integer, String> myHashMap2 = new HashMap<Integer, String>();
myHashMap1.put(3, "사이다");
myHashMap1.put(1, "커피");
myHashMap1.put(2, "우유");
System.out.println("myHashMap1값: "+myHashMap1); // myHashMap1값: {3=사이다, 2=우유, 1=커피}
myHashMap2 = myHashMap1;
myHashMap2.put(4,"콜라");
myHashMap2.put(5,"보리차");
System.out.println("myHashMap1값: "+myHashMap1); // myHashMap1값: {5=보리차, 4=콜라, 3=사이다, 2=우유, 1=커피}
System.out.println("myHashMap2값: "+myHashMap2); // myHashMap2값: {5=보리차, 4=콜라, 3=사이다, 2=우유, 1=커피}
System.out.println(myHashMap2.keySet()); // [5, 4, 3, 2, 1]
java.util.Iterator<Integer> myIterator = myHashMap2.keySet().iterator();
while(myIterator.hasNext()){
Integer key = myIterator.next();
System.out.println(key+myHashMap2.get(key));
}
// ---------------------------------- #case3----------------------------------------------
int a = 1;
int b;
b = a;
b = 10;
System.out.println("a값: "+a); // a = 1
System.out.println("b값: "+b); // b = 10
// ---------------------------------- #case4----------------------------------------------
String c = new String();
String d = new String();
c = "ccc" ;
d = c ;
d = "ddd";
System.out.println("c값: " + c); // c = ccc
System.out.println("d값: " + d); // d = ddd
// ---------------------------------- #case5----------------------------------------------
CallByValue callbyValue1 = new CallByValue();
callbyValue1.a = 200;
System.out.println("callbyValue1값: "+callbyValue1.a); // 200
CallByReference(callbyValue1);
System.out.println("callbyValue1값: "+callbyValue1.a); // 100
}
}