“Hapus elemen dari array di java” Kode Jawaban

Hapus elemen dari array di java


import java.util.Arrays;
import java.util.stream.IntStream;
 
class Main
{
    public static int[] remove(int[] a, int index) {
        if (a == null || index < 0 || index >= a.length) {		//lowering the possibilities of an error
            return a;
        }
 	
        else {
          return IntStream.range(0, a.length)
                        .filter(i -> i != index)
                        .map(i -> a[i])
                        .toArray();
        }
    }
 	
    public static void main(String[] args) {		//an example of how to use it
        int[] a = { 1, 2, 3, 4, 5 };
        int index = 2;
 
        a = remove(a, index);
        System.out.println(Arrays.toString(a));
    }
}
David Zlatin

Hapus elemen dari array di java


import java.util.Arrays;
import java.util.stream.IntStream;
 
class Main
{
    public static int[] remove(int[] a, int index) {
        if (a == null || index < 0 || index >= a.length) {		//lowering the possibilities of an error
            return a;
        }
 	
        else {
          return IntStream.range(0, a.length)
                        .filter(i -> i != index)
                        .map(i -> a[i])
                        .toArray();
        }
    }
 	
    public static void main(String[] args) {		//an example of how to use it
        int[] a = { 1, 2, 3, 4, 5 };
        int index = 2;
 
        a = remove(a, index);
        System.out.println(Arrays.toString(a));
    }
}
David Zlatin

Hapus elemen dari array di java


import java.util.Arrays;
import java.util.stream.IntStream;
 
class Main
{
    public static int[] remove(int[] a, int index) {
        if (a == null || index < 0 || index >= a.length) {		//lowering the possibilities of an error
            return a;
        }
 	
        else {
          return IntStream.range(0, a.length)
                        .filter(i -> i != index)
                        .map(i -> a[i])
                        .toArray();
        }
    }
 	
    public static void main(String[] args) {		//an example of how to use it
        int[] a = { 1, 2, 3, 4, 5 };
        int index = 2;
 
        a = remove(a, index);
        System.out.println(Arrays.toString(a));
    }
}
David Zlatin

hhow untuk menghapus elemen dari java

final int
Grumpy Goosander

Jawaban yang mirip dengan “Hapus elemen dari array di java”

Pertanyaan yang mirip dengan “Hapus elemen dari array di java”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya