Ad
Code
Diff
  • import java.util.*;
    import java.util.stream.*;
    
    public class Kata {
    
        public static int[] Remove(int[] integerList, int[] valuesList) {
            if (integerList == null) return new int[]{};
            if (valuesList == null) return integerList;
            
    		    List<Integer> list = toList(integerList);
            list.removeAll(toList(valuesList));
            return list.stream().mapToInt(i->i).toArray();
    	  } 
      
        private static List<Integer> toList(int[] arr) {
            return IntStream.of(arr).boxed().collect(Collectors.toList());
        }
    
    }
    • import java.util.Arrays;
    • import java.util.List;
    • import java.util.stream.Collectors;
    • public class Kata
    • {
    • public static int[] Remove(int[] integerList,int[] valuesList)
    • {
    • if (integerList==null||integerList.length<1) return new int[0];
    • if (valuesList==null||valuesList.length<1) return integerList;
    • List<Integer> list= Arrays.stream(valuesList).boxed().collect(Collectors.toList());
    • return Arrays.stream(integerList).filter(i->!list.contains(i)).toArray();
    • }
    • import java.util.*;
    • import java.util.stream.*;
    • public class Kata {
    • public static int[] Remove(int[] integerList, int[] valuesList) {
    • if (integerList == null) return new int[]{};
    • if (valuesList == null) return integerList;
    • List<Integer> list = toList(integerList);
    • list.removeAll(toList(valuesList));
    • return list.stream().mapToInt(i->i).toArray();
    • }
    • private static List<Integer> toList(int[] arr) {
    • return IntStream.of(arr).boxed().collect(Collectors.toList());
    • }
    • }

Another variant using IntStream. Probably much slower than using a for-loop.

Code
Diff
  • import java.util.stream.IntStream;
    
    public class Kata {
        public static int findIndex(int[] array, int target) {
            return IntStream.range(0, array.length).filter(i -> array[i] == target).findFirst().orElse(-1);
        }
    }
    • import java.util.Arrays;
    • import java.util.List;
    • import java.util.stream.Collectors;
    • import java.util.stream.IntStream;
    • public class Kata {
    • public static int findIndex (int[] array, int target) {
    • return Arrays.stream(array).boxed().collect(Collectors.toList()).indexOf(target);
    • public static int findIndex(int[] array, int target) {
    • return IntStream.range(0, array.length).filter(i -> array[i] == target).findFirst().orElse(-1);
    • }
    • }