본문 바로가기
TIL (Today I Learned)

TIL) Oracle에서 제공한 array Quiz

by Won's log 2023. 6. 5.

TIL 기준

1. 어떤 문제가 있었는지

2. 내가 시도해 본 것들

3. 어떻게 해결했는지

4. 뭘 새롭게 알았는지

=문시해알

 

오늘은 오라클에서 배열에 관해 배웠고 퀴즈 오답을 중점으로 가져왔다.

틀린 퀴즈

*빨간 글씨는 틀린 것

  1. The term "instance variable" is another name for non-static field.
  2. The term "class variable" is another name for static field.
  3. A local variable stores temporary state; it is declared inside a method.
  4. A variable declared within the opening and closing parenthesis of a method is called a parameter.
  5. What are the eight primitive data types supported by the Java programming language? byte, short, int, long, float, double, boolean, char
  6. Character strings are represented by the class java.lang.String.
  7. An array is a container object that holds a fixed number of values of a single type.

아직 까지 변수가 익숙하지 않다. 꾸준히 접해봐야지.

 

오라클에서 제공하는 Java Platform 중에서 array에 유용하게 사용되는 메서드를 가져왔다

예시
class ArrayCopyOfDemo {
    public static void main(String[] args) {
        String[] copyFrom = {
            "Affogato", "Americano", "Cappuccino", "Corretto", "Cortado",   
            "Doppio", "Espresso", "Frappucino", "Freddo", "Lungo", "Macchiato",      
            "Marocchino", "Ristretto" };
        
        String[] copyTo = java.util.Arrays.copyOfRange(copyFrom, 2, 9);        
        for (String coffee : copyTo) {
            System.out.print(coffee + " ");           
        }            
    }
}

Some other useful operations provided by methods in the java.util.Arrays class are:

Searching an array for a specific value to get the index at which it is placed (the binarySearch method).

Comparing two arrays to determine if they are equal or not (the equals method).

Filling an array to place a specific value at each index (the fill method).

Sorting an array into ascending order. This can be done either sequentially, using the sort method, or concurrently, using the parallelSort method introduced in Java SE 8. Parallel sorting of large arrays on multiprocessor systems is faster than sequential array sorting.

Creating a stream that uses an array as its source (the stream method). For example, the following statement prints the contents of the copyTo array in the same way as in the previous example:

java.util.Arrays.stream(copyTo).map(coffee -> coffee + " ").forEach(System.out::print);  
See Aggregate Operations for more information about streams.

Converting an array to a string. The toString method converts each element of the array to a string, separates them with commas, then surrounds them with brackets. For example, the following statement converts the copyTo array to a string and prints it:

System.out.println(java.util.Arrays.toString(copyTo)); 
This statement prints the following:

[Cappuccino, Corretto, Cortado, Doppio, Espresso, Frappucino, Freddo]

 

개발용어 [개발자들의 컨벤션]

public class Generic<T>에서 꺽쇠는 제네릿임을 표시한다

제네릭명으로는 T, U, V, E를 많이 사용한다고 한다.