자바

    Comparable

    Comparable

    지금도 어렵지만, 1단계, 2단계, 3단계... 이런 식으로 설명해 보겠다. 1단계 Intro - 자바조상님은 사용자가 만든 객체에 대해서는 모르신다. Arrays.sort() 메서드부터 이야기해보겠다. 아래의 코드를 보자 import java.util.Arrays; public class Exercise11_7 { public static void main(String[] args){ int[] arr1 = { 30, 50, 10, 40, 20}; Arrays.sort(arr1); //int, float 등 기본형 타입의 배열을 자바가 내부적으로 알아서 오름차순으로 정렬해준다. System.out.println("arr1= "+Arrays.toString(arr1)); Integer[] arr2 = {..

    Wrapper클래스

    Wrapper클래스 기본자료형을 객체 자료형으로 사용할 수 있도록 만들어 놓은 포장 클래스 코드실습 public class TPC39 { public static void main(String[] args) { int a =1; Integer b = 1; //컴파일러가 자동으로 new Integer(1)해서 Boxing해줌 int c =b.intValue();//Interger형을 기본자료형인 int형으로 Unboxing한다. System.out.println(c); Object[] obj = new Object[3]; obj[0] = new Integer(1); obj[1] = new Integer(2); obj[2] = new Integer(3); //Integer클래스는 Object클래스의 toSt..

    ArrayList

    ArrayList 특징 : Object[ ] 배열의 데이터구조를 갖고 있다. 배열의 길이에 제약이 없다. 1. 실행클래스를 만든다. import java.util.ArrayList; import kr.bit.Book; public class TPC37 { public static void main(String[] args) { ArrayList list = new ArrayList(); //Object[] 배열을 가지고 있음 list.add(new Book("자바", 12000,"이지스", 600)); //add동작 : upcasting (Book타입-->Object타입) list.add(new Book("C언어", 17000,"에이콘", 700)); list.add(new Book("Python", 1..

    내가 만든 최초의 API - IntArray, ObjectArray

    IntArray 1. IntArray배열클래스를 만든다. public class IntArray { private int count; //int는 값을 대입하지 않는 경우 0으로 초기화 private int[] arr; public IntArray() { this(10); } public IntArray(int init) { arr= new int[init]; } public void add(int data) { arr[count++]=data; //count++은 후위 연산자로써 //일단 arr[0]이 실행된 후 arr[1]로 증가 } public int get(int index) { return arr[index]; } public int size() { return count; } } 2. IntA..