SHARE
TWEET

delete form array

DulcetAirman Sep 13th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.claude_martin;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class SomeClass {
  6.  
  7.   public static void main(String[] args) {
  8.     String[] data = { "Batman", "Wonder Woman", "Superman", "Phoenix", "Spider-Man", "Jessica Jones", "Hulk" };
  9.     // filter
  10.     String[] filtered0 = Arrays.stream(data).filter(x -> x.contains("e")).toArray(String[]::new);
  11.     // remove first
  12.     String[] filtered1 = Arrays.stream(data).skip(1).toArray(String[]::new);
  13.     // remove last
  14.     String[] filtered2 = Arrays.stream(data).limit(data.length - 1).toArray(String[]::new);
  15.     // remove data[i]
  16.     String[] filtered3 = Arrays.stream(data).filter(x -> x != data[3]).toArray(String[]::new);
  17.    
  18.     System.out.println(Arrays.toString(filtered0));
  19.     System.out.println(Arrays.toString(filtered1));
  20.     System.out.println(Arrays.toString(filtered2));
  21.     System.out.println(Arrays.toString(filtered3));
  22.   }
  23.  
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top