💻 Computer/🦀 Java15 [Java] Collection Collection이 뭘까? Collection 은 Interface이며 List의 부모 클래스이며 이 말뜻은 List관련 클래스들은 모두 Collection 을 상속 받는다 라고 생각해도 될듯 하다 2022. 7. 25. [Java] Comparable<T> , Comparator<T> 이게 뭔데? 객체를 비교, 정렬하는 것이다. Comparable과 Comparator의 차이점 Comparable은 자기 자신의 객체와 비교하는것 Comparator은 다른 객체와 비교하는 것이라는 차이점이 있다. 어떻게 쓰는 거? import java.util.Arrays; class Person implements Comparable{ int age; public Person(int age){ this.age = age; } public int compareTo(Person o){ return this.age - o.age; } } public class Main{ public static void main(String[] args){ Person[] arr = new Person[10]; for(i.. 2022. 7. 25. [Java] Generic Generic이란? class hello{ T name; public hello(T name){ this.name = name; } } 를 Generic이라 부른다. 아래 코드를 보자 class Hello{ T text; public Hello(T text){ this.text = text; } void hi(){ System.out.println(text); } } public class Main{ public static void main(String[] args){ Hello hello = new Hello("안녕"); hello.hi(); } } //출력 안녕 이 코드를 나중에 까먹었을 수 도 있는 나를 위해 차근차근 설명해보자면 Class Hello type을 지정할 수 있는 Generic Cl.. 2022. 7. 23. [Java] String을 자세히 String 이란? 우리가 알고 있는 그 문자열 그 String 맞다 String의 메모리 관리 String의 메모리 관리란 String이 생성되고 만들어질 때 어떤 식으로 저장되는지에 대해 알아보는 것이다 일단 String의 사용법은 두 가지 있다 String str1 = "hello"; //문자열 리터럴 방식 Stirng str2 = new String("hello"); //객체 생성 방식 위의 두 코드를 비교해보자 String str1 = "hello" String str2 = new String("hello") System.out.println(" == : " + str1 == str2); System.out.println("equals : " + str1.equals(str2)); //출력 ==.. 2022. 7. 22. [Java] Arrays.asList()은 무엇인가 Arrays.asList() 란? 일반 배열을 ArrayList로 바꿔준다. int[] Int_Array = {1,2,3,4,5}; List list = Arrays.asList(Int_Array); Arrays.asList()의 리턴 값 ArrayList (a)를 리턴하는 모습을 알 수 있다. 여기서 ArrayList ()는 우리가 흔히 아는 그 ArrayList Class가 아닌 Arrays class 안에 따로 정의된 private static class이다 (add 함수가 정의되어 있지 않다) //Java Arrays.class 파일 public static List asList(T... a) { return new ArrayList(a); } Arrays.asList() 알아야 할 점 밑의 코드.. 2022. 7. 21. Java this 와 super 오늘은 Java의 this와 super에 대해 알아보려고 한다 This public class Main { public static void main(String[] args) { Person p = new Person(12, "tom"); p.hi("hana"); // 출력 // method : hana // this : tom } } class Person { int age; String name; public Person(int age, String name) { this.age = age; this.name = name; } public void hi(String name) { System.out.printf("method : %s\nthis : %s", name, this.name); } } t.. 2022. 7. 17. 이전 1 2 3 다음