Advertisement
Guest User

Test

a guest
Mar 25th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3.  
  4. public class MyClass {
  5.  
  6.     public static ArrayList<String> removeAll_My(ArrayList<String> z, int[] ii) {
  7.         if(ii.length==0) return z;
  8.         ArrayList<String> nz = new ArrayList<String>();
  9.         Arrays.sort(ii);
  10.         int prev=0;
  11.         for (int x = 0; x < ii.length; x++ ) {
  12.             if(ii[x]-prev>0)
  13.                 nz.addAll(z.subList(prev,ii[x]));
  14.             prev=ii[x]+1;
  15.         }
  16.         if(prev<z.size()){
  17.             nz.addAll(z.subList(prev,z.size()));
  18.         }
  19.         return nz;
  20.     }
  21.    
  22.     public static void removeAll_Ki(ArrayList<String> z, int[] ii) {
  23.         if(ii.length==0) return;
  24.         Arrays.sort(ii);
  25.         for (int x = ii.length-1; x >= 0; x--) {
  26.             z.remove(ii[x]);
  27.         }      
  28.     }    
  29.    
  30.    
  31.     public static void main(String[] args) {
  32.        
  33.         ArrayList<String> x = new ArrayList<String>();
  34.         ArrayList<String> r = new ArrayList<String>();
  35.        
  36.        
  37.         for(int i=0; i<100000; i++)
  38.             x.add(String.format ("%05d", i));
  39.         int[] myArray;
  40.         myArray = new int[30000];
  41.         for(int i=0; i<30000; i++)
  42.             myArray[i]=i*3;
  43.         long  startTime = System.nanoTime ();
  44.         for(int i=0; i<1; i++)
  45.             removeAll_Ki(x,myArray);
  46.         long  stopTime = System.nanoTime ();
  47.         System.out.println("Kir:" + (stopTime  - startTime ));
  48.         x = new ArrayList<String>();
  49.         for(int i=0; i<100000; i++)
  50.             x.add(String.format ("%05d", i));
  51.         startTime = System.nanoTime ();
  52.         for(int i=0; i<1; i++)
  53.             r = removeAll_My(x,myArray);
  54.         stopTime = System.nanoTime ();
  55.         System.out.println("My:" + (stopTime  - startTime ));
  56.     }
  57.  
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement