반응형
package String;
public class Main {
public static void main(String[] args) {
// two ways of initializing String
String myString = new String("i love java");
String myString2 = "i love java";
if(myString.equals(myString2)) {
System.out.println("strings are equal");
}
System.out.println(myString.length());
System.out.println(myString.charAt(5));
System.out.println(myString.indexOf('o'));
String strs[] = myString.split(" ");
// changing the strings
// original strs[2] is collected in garbage collector
// so it is not mutating but making the new one
strs[2] = "coding, with Sam";
for (String str : strs) {
System.out.print(str + " ");
}
}
}
반응형
'Programming > Java' 카테고리의 다른 글
2022년 3월 14일 배열 (0) | 2022.03.14 |
---|---|
3월 12일 배운 것 (0) | 2022.03.14 |
Java Regression problem (0) | 2022.02.19 |
Linked List (0) | 2022.02.10 |
퀵 정렬 자바 (0) | 2022.02.10 |