import java.util.Arrays;
import java.util.stream.IntStream;
class Main {
public static void main(String[] args) {
new ver2().run();
System.out.printf("\n");
new ver2_1().run();
System.out.printf("\n");
}
}
for문 방식
class ver1{
public void run(){
int[] arr ={1,2,3,4,5,6,7,8,9,10};
for ( int i=0; i< arr.length; i++){
arr[i-1] *= 2 ;
}
System.out.printf("%s", Arrays.toString(arr));
}
}
stream 방식 1
class ver2{
public void run() {
int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] result = Arrays.stream(arr)
.map(e -> {
return e*2;
})
.toArray();
System.out.printf("%s\n", Arrays.toString(arr));
System.out.printf("%s", Arrays.toString(result));
}
}
stream 방식 1
class ver2_1{
public void run() {
int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] result = Arrays.stream(arr)
.map(e -> e*2)
.toArray();
System.out.printf("%s", Arrays.toString(result));
}
}