API
- ApplicationProgramningInterface
기능, 클래스, 인터페이스를 구현하는 문서.
자바 Document
/** document주석!!
*
* 학생 정보를 담는 클래스이다.
*
*/
public class Student {
/**
* 학생 이름
*/
private String myName;
/**
* 학생 나이
*/
private int age;
/**
*학생 이름을 변환하는 메서드
*
*/
public String getMyName() {
return myName;
}
/**
*
*학생이름을 등록하는 메서드
*/
public void setMyName(String myName) {
this.myName = myName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class StringCompareExam {
public static void main(String[] args) {
String apple1 = "사과";
String apple2 = "사과";
String apple3 = new String("사과");
//비교
System.out.println("apple1 == apple2 : " +(apple1 == apple2));
System.out.println("apple3 == apple2 : " +(apple3 == apple2));
//객체의 위치값 출력
System.out.println(" apple1 : " + System.identityHasyCode(apple1));
System.out.println(" apple2 : " + System.identityHasyCode(apple2));
System.out.println(" apple3 : " + System.identityHasyCode(apple3));
}
}
-> apple1 == apple2 : true
apple3 == apple2 : false
apple1 : 1365202186
apple2 : 1365202186
apple3 : 1651191114
public class StringTest {
public static void main(String[] args) {
String str = "오늘은 비가 너무 많이 옵니다. 다들 비를 조심하세요.";
System.out.println("문장의 길이 : "+ str.length());
System.out.println("문장 추출 : "+ str.charAt(11));
System.out.println("해당 문자 위치 : "+ str.indexOf("이");
System.out.println("해당 문자 마지막 위치 : "+ str.lastIndexOf("비"));
String str2 = "11오늘은 비22가 너무 많이 옵니다. 33다들 비를 조심하세요.";
System.out.println("str2.replaceAll("[0-9]", ""));
String str3 = "오늘은 날씨가 험하니 집에 일찍 귀가하세요.";
System.out.println(str3.substring(11));
System.out.println(str3.substring(0, 10));
}
}
-> 문장의 길이 :30
문장 추출 :이
해당 문자 위치 :4
해당 문자 마지막 위치 :21
오늘은 비가 너무 많이 옵니다. 다들 비를 조심하세요.
집에 일찍 귀가하세요.
오늘은 날씨가 험하
실습)
public class StringBuilderTest {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append("안녕하세요\n"); // 이전 문장 뒤에 붙는다.
sb. append("만나서 반갑습니다");
System.out.println(sb);
//삭제
//- delete(int start, int end); start <= x < end
sb.delete(0, 5);
System.out.println(sb);
//삽입
sb.insert(5, "안녕히세요");
System.out.println("=====================");
System.out.println(sb);
System.out.println("=====================");
System.out.println(sb.reverse());
}
}
-> 안녕히세요
만나서 반갑습니다
만나서 반갑습니다
=====================
안녕히세요
만나서 반갑습니다
=====================
다니습갑반 서나만
요세하녕안
public class WrapperTest01 {
public class WrapperTest01 {
public static void main(String[] args) {
Integer num01 = 10; // autoBoxing 가능
//Integer num02 = new Integer(10); // 이제 사용 불가.
Integer num03 = Integer.valueof(10);
Integer num04 = Integer.valueof("10"); // 문자타입 숫자(정수) --> 정수
Double dnum 01 = 10.11;
Double dnum02 = Double.valueOf("10.11");
Double dnum03 = Double.valueOf("10");
System.out.println("정수 : " + num01);
System.out.println("실수 : " + num02);
}
}
-> 정수 : 10
실수 : 10.11
public class WrapperTest02 {
public static void main(String[] args) {
String inStr = "70";
String doubleStr = "60.77";
/*
* 정수 경우
* valueof() --> 정수 또는 문자형 타입 정수, 리턴타입 : Integer
* ParseInt() --> 문자형 타입 정수, 리턴타입 : int
*/
int myScore = Integer.parseInt(intStr);
double cutLine = Double.parseDouble(doubleStr);
if(myScore >= cutLine) {
System.out.println("합격!");
}else {
System.out.println("불합격!");
}
}
}
-> 합격!