Java 학습노트:문자열 처리
1637 단어 java 문자열
package myjava;
public class Mystring {
public static void main(String args[]) {
String strOrig = "ken,Hello dog!Good job!Hello world!";
// [lastIndexOf: ,indexOf: ]
// int lastIndex = strOrig.lastIndexOf("Hello");
int Index2 = strOrig.indexOf("Hello");
if (Index2 == -1) {
System.out.println(" ");
} else {
System.out.println(" " + Index2);
}
//
String newStr = strOrig.substring(4);
System.out.println(newStr);
//
System.out.println(newStr.replace("dog", "King"));
System.out.println(newStr.replaceAll("Hello", "Great"));
System.out.println(newStr.replaceFirst("Hello", "lalalal"));
//
String oldChar = "abcdef";
String newChar = new StringBuffer(oldChar).reverse().toString();
System.out.println(" :" + newChar);
//
String deChar = "hava-a-good-time";
String[] deArr;
deArr = deChar.split("-");
for (String item : deArr) {
System.out.println(" :" + item);
}
//
String bigStr = "JUST DO IT";
String smStr = bigStr.toLowerCase();
System.out.println(" :" + smStr);
String newBigStr = smStr.toUpperCase();
System.out.println(" :" + newBigStr);
//
String firstStr = "kens";
String secondStr = "kena";
boolean comResult = firstStr.regionMatches(0, secondStr, 0, 4);
System.out.println(" :" + comResult);
}
}