ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 배열생성
    JAVA 2020. 5. 6. 18:47

     

    int[] a new int[3];

                

                int[] b;

                b = new int[3];

                

                //선언된 변수가 배열변수가 아니다

                //int c;

                //c = new int[3]; // error

                

                //배열만들기

                ArrayList<String> tmpAry = new ArrayList<>();

                

                //배열입력

                tmpAry.add("aaa");

                tmpAry.add("bbb");

                

                //출력

                System.out.println(tmpAry); //배열출력

                System.out.println(tmpAry.get(1)); //원하는 위치의 배열값출력

                System.out.println(tmpAry.indexOf("bb")); //해당값을 가지고잇는 index출력

                

                

                tmpAry.forEach(idx -> System.out.println(idx)); // 반복문으로 한개 씩 출력

                

                //arraylist to array

                String[] tmpArys = new String[tmpAry.size()];

                int cnt = 0;

                for(String tmp : tmpAry)

                {

                      tmpArys[cnt++] = tmp;

                }

                

                System.out.println(Arrays.toString(tmpArys));

     

     

     

     

    'JAVA' 카테고리의 다른 글

    자바문법  (0) 2020.07.14
    @override, @overload  (0) 2020.07.14
    메소드  (0) 2020.05.06
    상속 extends  (0) 2020.05.06
    배열출력  (0) 2020.05.06

    댓글

Designed by Tistory.