IT/JAVA

자바 흔히 쓰이는 함수 정리 (문자열)

KeepGooing 2020. 6. 25. 10:04
반응형


public class CoTe7 {

public static void main(String [] args) {
int stopCnt = 1;
StringBuilder sb = new StringBuilder();
while (stopCnt <= 10000/5) {
for (int i = 1; i <= 5; i ++) {
sb.append(i);
stopCnt++;
}
}
String a = "a";
String B = "B";
String b = "b";
String abc = "abc";

int result = a.compareTo(b);
System.out.println(result);

int result2 = a.compareToIgnoreCase(B);
System.out.println(result2);

char result3 = a.charAt(0);
System.out.println(result3);

boolean result4 = abc.contains("a");
System.out.println(result4);

boolean result5 = abc.endsWith("c");
System.out.println(result5);

boolean result6 = B.equals(b);
System.out.println(result6);

boolean result7 = B.equalsIgnoreCase(b);
System.out.println(result7);

char [] arr = abc.toCharArray();

for(char tray2 : arr) {
System.out.println("tray2"+tray2);
}


StringBuffer sb1 = new StringBuffer();
sb1.append("Hello");
sb1.append(" ");
sb1.append("I am a software developer!");
System.out.println(sb1.toString());

StringBuilder sb2 = new StringBuilder();

sb2.append("Hello");
sb2.append("Hello2");
System.out.println(sb2.toString());


try {

byte[] result8 = a.getBytes("UTF-8");
System.out.println(result8);

String decoded = new String(result8, "UTF-8");
System.out.println("decoded: " + decoded);
} catch (Exception e) {
e.printStackTrace();
}

String [] arrAbc = abc.split("");
for (String tray : arrAbc) {
System.out.println(tray);
}

int idx = abc.indexOf("b");
System.out.println(idx); //1

boolean isEmp = a.isEmpty();
System.out.println(isEmp);//false;

int idx2 = abc.lastIndexOf("c");
System.out.println(idx2); //2

abc.length();

boolean mat = abc.matches("a.*");
boolean mat2 = abc.matches("(.*)a");
System.out.println(mat);
System.out.println(mat2);

String rep = abc.replace("a", "*");
System.out.println(rep);

String repAl = abc.replaceAll("a", "*");
System.out.println(repAl);

String [] spl = abc.split("");
System.out.println(spl[0]);

boolean stW = abc.startsWith("a");
System.out.println(stW);

String subs = abc.substring(0,1);
System.out.println(subs);

String tUC = abc.toUpperCase();
System.out.println(tUC);

String abcd =" abcd ";
System.out.println(abcd);

String tm = abcd.trim(); // 앞 뒤의 whitespace 제거
System.out.println(tm);

String val = String.valueOf(10);
Double val2 = Double.valueOf(10);
System.out.println(val);
System.out.println(val2);

 }

}

반응형