자료형
Number
Boolean
문자 - char : 하나의 문자
문자열 - String : 여러개의 문자
String a = "Hello";
System.out.println(a.equals("Hello"));
String a = "hello java";
System.out.println(a.substring(0, 5)); // hello
StringBuffer : 문자열을 추가하거나 변경할 때 사용되는 자료형, String객체는 immutable 하다.
StringBuffer sb = new StringBuffer();
sb.append("hello");
sb.append(" ");
sb.append("world");
String result = sb.toString();
System.out.println(result); // hello world
StringBuffer sb = new StringBuffer();
sb.append("world");
sb.insert(0, "hello ");
System.out.println(sb.toString()); // hello world
StringBuffer sb = new StringBuffer();
sb.append("Hello jump to java");
System.out.println(sb.substring(0, 4));
배열 (Array) : 특정 자료형의 집합, 길이는 고정되어 있다.
리스트 (List) : 리스트는 크기가 정해져 있지 않고 동적으로 변한다
import java.util.ArrayList; // import 해야 사용할 수 있다.
public class Sample {
public static void main(String[] args) {
ArrayList pitches = new ArrayList();
pitches.add("142");
pitches.add(0, "133");
}
}