Java

Arrays 실습

헝그리하트 2013. 3. 20. 17:46

import java.util.Arrays;

 

 

public class ArrsysEx {

 

           /**

            @param args

            */

           public static void main(String[] args) {

                     // TODO Auto-generated method stub

                     String[] arr1 = new String[10];

                    

                     //배열 초기화 메서드

                     Arrays.fill(arr1, "hello");

                    

//                  for (String str : arr1){

//                             System.out.println(str);

//                  }

                    

                     Arrays.fill(arr1, 1, 5, "world");

                    

                     for (String str : arr1){

                                System.out.println(str);

                     }

                    

                                         

           }

 

}

hello

world

world

world

world

hello

hello

hello

hello

hello

 

import java.util.Arrays;

 

 

public class ArraysEx {

 

           /**

            @param args

            */

           public static void main(String[] args) {

                     // TODO Auto-generated method stub

                     int[] ar1 = {20, 4, 5, 40, 0, 1, 10};

                    

                     Arrays.sort(ar1);

                     for(int i : ar1){

                                System.out.print(i + "\t");

                     }

           }

 

}

0         1         4         5         10       20       40