๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

[JAVA ์ฝ”๋”ฉ ์ดˆ๋ณด] Stack (๋ฆฌ์ŠคํŠธ) Method ๋ณธ๋ฌธ

๐Ÿฆฅ ์ฝ”ํ…Œ/JAVA

[JAVA ์ฝ”๋”ฉ ์ดˆ๋ณด] Stack (๋ฆฌ์ŠคํŠธ) Method

์ง•์ง•์•ŒํŒŒ์นด 2023. 7. 16. 16:31
728x90
๋ฐ˜์‘ํ˜•

<๋ณธ ๋ธ”๋กœ๊ทธ๋Š” codechacha ๋‹˜์˜ ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค :-)>

 

๐Ÿ’— Stack Method

๐Ÿ‰ ์š”์†Œ ์ถ”๊ฐ€ & ์ œ๊ฑฐ & ๋น„์šฐ๊ธฐ & ์œ ๋ฌด ํ™•์ธ

import java.util.*;
import java.io.*;

// tip: each public class is put in its own file
public class main
{
    // tip: arguments are passed via the field below this editor
    public static void main(String[] args)
    {
        ArrayList<Integer> list = new ArrayList<>(Arrays.asList(0, 3, 2, 1, 5));
        System.out.println(list); // [0, 3, 2, 1, 5]

        //์ •์ˆ˜ํ˜• List ์›์†Œ ์ค‘ ์ตœ๋Œ€, ์ตœ์†Œ๊ฐ’ 
        System.out.println(Collections.max(list));
        System.out.println(Collections.min(list));

        //List ์ •๋ ฌ
        Collections.sort(list);                                // ์˜ค๋ฆ„์ฐจ์ˆœ (ASC)
        System.out.println(list);
        Collections.sort(list, Collections.reverseOrder());    // ๋‚ด๋ฆผ์ฐจ์ˆœ (DESC)
        System.out.println(list);

        //List ๋’ค์ง‘๊ธฐ
        Collections.reverse(list);
        System.out.println(list);

        //List ๋‚ด ์›์†Œ์˜ ๊ฐฏ์ˆ˜ ๋ฐ˜ํ™˜
        System.out.println(Collections.frequency(list, 3));
    }
}

 

728x90
๋ฐ˜์‘ํ˜•
Comments