*์คํธ๋ง ๊ฐ์ฒด๋ ์์ ๋ถ๊ฐ๋ฅ
public class StringEx {
public static void main(String[] args) {
String str1 = "abcd";
String str2 = new String("abcd");
char[] data = {'a', 'b', 'c', 'd'};
String str3 = new String(data);
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
System.out.println(str1.concat("efgh")); //1ํ์ฑ
str1 = str1.concat("efgh"); //๊ณ์ ์ด์ด์ง๊ฒ ํ๋ ค๋ฉด
System.out.println(str1);
}
}
StringBuffer ๋ฌธ์์ด ๋ฐ๊พธ๋ ๋ฐฉ๋ฒ
public class StringEx {
public static void main(String[] args) {
String str1 = "ab cd";
String str2 = new String("a,b,c,d");
char[] data = {'a', 'b', 'c', 'd'};
String str3 = new String(data);
StringBuffer sb = new StringBuffer("Java ");
System.out.println(sb);
sb.append("Program");
System.out.println(sb);
sb.insert(4, "**");
System.out.println(sb);
}
}
StringTokenizer
import java.util.StringTokenizer;
public class StringTokenizerEx {
public static void main(String[] args) {
String str = "Python,Java,Network,Database";
StringTokenizer st = new StringTokenizer(str, ",");
while(st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
}
}
๊ฒฐ๊ณผ
728x90
๋ฐ์ํ
0