class AAA {
void s(int p1, int p2) {
...
}
void s(int p1, double p2) {
...
}
}
AAA inst = new AAA();
inst s(7,'k');
// char는 double보다 int와 가까우므로 s(int p1, int p2)가 호출된다
// 무슨 메소드가 호출될지 모호하므로 인자로 전달되기 전 (int)로 강제 형변환을 해주는 것이 옳다
// 이런 모호한 상황을 애초에 만들지 말자
class Person
private int regiNum;
private int passNum;
Person(int rnum, int pnum) {
regiNum = rnum;
passNum = pnum;
}
Person(int rnum) {
// regiNum = rnum;
// passNum = 0;
this.(rnum, 0);
}
class SimpleBox() {
private int data;
SimpleBox(int data) {
this.data = data;
}
}
String st1 = new String("apple");
String st2 = "apple";
void println() {...};
void println(int i) {...};
void println(String str) {...};
class ImmutableString {
public static void main(String[] args) {
String str1 = "Simple String";
String str2 = "Simple String";
String str3 = new String ("Simple String");
String str3 = new String ("Simple String");
}
}
public static void main(String[args]) {
String str1 = "Simple String";
String str2 = str1;
}
public static void main(String[args]) {
String str1 = "Simple String";
String str2 = new String("Simple String");
}
public static void main(String[args]) {
String str = "two";
switch(str) {
case "one":
...
break;
case "two":
...
break;
}
default:
...
}
}
class StringConcat {
public static void main(String[args]) {
String str1 = "Coffee";
String str2 = "Bread";
String str3 = str1.concat(str2);
String str4 = "Fresh".concat(str3);
}
}
String str = "abcdefg";
str.substring(2); // "cdefg"
str.substring(2, 4); // "cd"
public static void main(String[args]) {
String st1 = "Lexicographically";
String st2 = "lexicographically";
int cmp;
if(st1.equls(st2))
...
else
...
cmp = st1.compareTo(st2);
if(cmp == 0) // 일치
...
else if(cmp < 0) // 사전의 앞에 위치하는 문자열 : st1
...
else // 사전의 앞에 위치하는 문자열 : st2
if(st1.compareToIgnoreCase(st2) == 0) // 대소비교는 하지 않는다
...
else
...
}
double e = 2.718281;
String se = String.valuOf(e);
System.out.println("funny"+camp");
위의 코드를 컴파일러가 아래 코드로 바꿔준다
System.out.println("funny".concat("camp"));
String str = "funny";
str += "camp"
str += "camp";
을 컴파일러가 str.concat("camp");
로 바꾼다string str = "age" + 17;
이 아니라string str = "age".concat(String.valueOf("17"));
String str = "AB".concat("CD").concat("EF");
String birth = "<양>"+7+"."+"16";
String birth = (new StringBuilder("<양>").append(7).append('.').append(16)).toString();