Java Basic Questions Program to write a product of array except itself
Anonymous
import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; class GFG { // Function to remove the element public static int[] removeTheElement(int[] arr, int index) { // If the array is empty // or the index is not in array range // return the original array if (arr == null || index = arr.length) { return arr; } // Create ArrayList from the array List arrayList = IntStream.of(arr) .boxed() .collect(Collectors.toList()); // Remove the specified element arrayList.remove(index); // return the resultant array return arrayList.stream() .mapToInt(Integer::intValue) .toArray(); }
Check out your Company Bowl for anonymous work chats.