✨
Java
  • 자바의 역사
  • Ch1
    • Before Start Java
      • History of Java
      • Feature of Java
      • API Documentation
      • Hello World!
      • eclipse shortcut
      • Eclipse IDE
      • GitHub to eclipse
  • Ch2
    • Variable
      • Variable
    • Variable Type
    • Character and String
    • Primitive type and range
    • printf and formatter
    • Scanner
    • Overflow of Int
    • Transition between different variable types
    • Object Array
  • CH3
    • Operator
  • CH4
    • 조건문과 반복문
    • if statement
    • switch
    • Math.random()
    • for statement
    • while statement
    • break, continue, named iterated statement
  • CH5
    • Array
    • 배열 활용
    • String Array
  • OOP
    • Intro
  • Class and Object
  • Make multiple Classes in one file
  • How to use Object
  • Object Array
  • Variable type according to declared location
  • Class Variable and Instance Variable
  • Method
  • Call Stack
  • Parameter
  • Static method(Class method) and Instance method
  • (Method)Overloading
  • Constructor
  • Constructor this()
  • Reference type variable "this"
  • Initialize variable
  • Inheritance
  • Composite
  • Single Inheritance, Object Class
  • (Method)Overriding
  • super, super()
  • package, class path
  • import, static import
  • modifier
  • access modifier
  • Encapsulation
  • Polymorphism
  • reference type transition
  • instanceof operator
  • Parameter polymorphism
  • Multiple object using one array
  • Abstract Class, Abstract Method
  • Creating Abstract Class
  • Interface
  • Interface Polymorphism
  • Interface Pros
  • Default method and static method
  • Inner Class
  • Anonymous Class
  • java.lang package and useful class
    • Object class
    • hashCode(), toString()
    • String class
    • StringBuffer class
    • StringBuilder class
    • Math class
    • Wrapper class
    • Number class
    • String to Number, String to Wrapper class
    • Auto-boxing and (auto)Unboxing
  • Collection Framework
    • Collections framework
    • List, Set, Map Interface
    • List의 removeAll() 과 clear() 비교
    • List Interface - ArrayList
    • How to view Java API source
    • List Interface - LinkedList
    • Stack and Queue
    • Iterator, ListIterator, Enumeration
    • Array
    • Comparator와 Comparable
    • Stack
    • String
    • String + char = String
    • String.toCharArray()
    • BufferedReader / BufferWriter
    • Scanner로 String 입력 - next( )와 nextLine( )
    • 공백없이 2차원배열 데이터 String으로 한번에 한줄씩 입력받기(문자/숫자)
    • 공백을 사이에 두고 빠른 2차원 배열 입출력
    • arr[index++]과 arr[index] index++의 차이
    • int와 long의 차이
    • Untitled
    • 타입 간의 변환
    • Array 와 ArrayList
    • valueOf()
    • Char
    • 변수, 객체 초기화(초기값 설정)
  • error troubleshooting
    • No enclosing instance of type
    • ASCII Code Table
    • java.lang.NumberFormatException
    • No enclosing instance..
  • reference
    • String을 생성하는 2가지 방법과 차이점
    • StackOverflowError(스택, 힙 메모리)
    • swtich-case 반복문
Powered by GitBook
On this page

Was this helpful?

  1. Collection Framework

Array

  1. Print Array - toString()

//by overloading method
static String toString(boolean[] a)
static String toString(byte[] a)
static String toString(char[] a)
static String toString(short[] a)
static String toString(int[] a)
static String toString(long[] a)
static String toString(float[] a)
static String toString(double[] a) 
static String toString(Object[] a) 

2. Copy Array - copyOf(), copyOfRange()

int[] arr = {0,1,2,3,4};
int[] arr2 = Arrays.copyOf(arr,arr.length);//arr2 = [0,1,2,3,4]
int[] arr3 = Arrays.copyOf(arr,3);//arr3 = [0,1,2]
int[] arr4 = Arrays.copyOf(arr,7);//arr4 = [0,1,2,3,4,0,0]
int[] arr5 = Arrays.copyOfRange(arr,2,4);//arr5 = [2,3], does not including 4
int[] arr6 = Arrays.copyOfRange(arr,0,7);//arr6 = [0,1,2,3,4,0,0]

3. Fill out Array - fill( ), setAll() - fill( ): Fill out with specific vaue(number,...) - setAll() : Fill out with Lambda.

int[] arr = new int[5];
Arrays.fill(arr,9);//arr=[9,9,9,9,9]
// 1 <= x < 6
//arr=[1,5,2,1,1]
Arrays.setAll(arr,(i) -> (int)(Math.random()*5)+1);

4. Sort and Serarch Array - sort(), binarySearch() - binarySearch() : Only when array is sorted. So, you should sort the array first.

int[] arr = {3,2,0,1,4};
int idx = Arrays.binarySearch(arr,2);//idx=-5 <- wrong result.

Arrays.sort(arr);
System.out.println(Arrays.toString(arr));//[0,1,2,3,4]
int idx = Arrays.binarySearch(arr,2);//idx=2 <-correct result.

5. Print Multiple-dimensional Array - deepToString( )

int[] arr = {0,1,2,3,4};
int [][] arr2D = {{11,12},{21,22};

System.out.println(Arrays.toString(arr));
System.out.println(Arrays.deepToString(arr2D));//[[11,12],[21,22]]

6. Compare Multiple-dimensional Array - deepEquals( )

String[][] str2D = new String[][]{{"aaa","bbb"},{"AAA","BBB"}};
String[][] str2D2 = new String[][]{{"aaa","bbb"},{"AAA","BBB"}};

System.out.println(Arrays.equals(str2D,str2D2));//false
System.out.println(Arrays.deepEquals(str2D,str2D2));//true

7. Casting Array to List - asList(Object ...a) - asList(Object...a) : Mutable parameter. The number of parameter is not defined. - List is for read data.

List list = Arrays.asList(new Integer[]{1,2,3,4,5});
List list = Arrays.asList(1,2,3,4,5);
//지원하지 않는 기능이기 때문에.
list.add(6);//UnsupportedOperationException 예외 발생

List list = new ArrayList(Arrays.asList(1,2,3,4,5));
  • 배열 출력

int[] iArr = {100,95,80,70,60};
System.out.println(iArr);//[I@14318bb] 같은 형식의 문자열 출력

char[] chArr = {'a','b','c','d'};
System.out.println(chArr);//abcd 출력
  • 배열 출력 - Arrays.toString() 이용(많이 사용) : iArr의 배열 값들을 String으로 바꿔주고 이 String을 출력한다. 한번에 출력되기 때문에 편하다.

System.out.println(Arrays.toString(iArr));
PreviousIterator, ListIterator, EnumerationNextComparator와 Comparable

Last updated 4 years ago

Was this helpful?