“Usuń element z tablicy w Javie” Kod odpowiedzi

Usuń element z tablicy w Javie


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

Usuń element z tablicy w Javie


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

Usuń element z tablicy w Javie


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

How, aby usunąć elementy z Java

final int
Grumpy Goosander

Odpowiedzi podobne do “Usuń element z tablicy w Javie”

Pytania podobne do “Usuń element z tablicy w Javie”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu