SHARE
TWEET

Untitled

viktoria_shulha Apr 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.epam.shulha.collections;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5.  
  6. public class Circle {
  7.     public static void main(String[] args) {
  8.  
  9.         ArrayList<String> circle = new ArrayList<>();
  10.  
  11.         circle.add("54");
  12.         circle.add("32");
  13.         circle.add("88");
  14.         circle.add("75");
  15.         circle.add("53");
  16.         circle.add("6");
  17.         circle.add("0");
  18.         circle.add("846");
  19.  
  20.         System.out.println("List before " + circle);
  21.  
  22.         removeEachSecondElement(circle);
  23.         System.out.println("List after " + circle);
  24.  
  25.     }
  26.  
  27.     private static void removeEachSecondElement(ArrayList<String> circle) {
  28.         Iterator<String> iterator = circle.iterator();
  29.         while (iterator.hasNext()) {
  30.             for (int i =0; i<circle.size(); i++) {
  31.                 String number = iterator.next();
  32.                 if (!(i % 2 == 0) ) {
  33.                    circle.remove(number);
  34. //                   ArrayList<String> newArray = new ArrayList<>();
  35. //                   newArray.add(number);
  36.  
  37.                     System.out.println("Remove " + number);
  38.                 } else {System.out.println("Not remove");}
  39.             }
  40.         }
  41.     }
  42. }
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