Facebook
From ДОМАШНА РАБОТА, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 41
  1. public static void main(String[] args) {
  2.         //POINT 1) create arrayList
  3.         System.out.println("Createing list...");
  4.  
  5.         ArrayList<Integer> numbers = new ArrayList<Integer>();
  6.  
  7.         System.out.println("Adding numbers...");
  8.  
  9.         //POINT 2) add numbers to arrayList
  10.         numbers.add(3);
  11.         numbers.add(5);
  12.         numbers.add(1);
  13.         numbers.add(4);
  14.         numbers.add(6);
  15.  
  16.         System.out.println("-----------------------------");
  17.         System.out.println("List with added numbers");
  18.  
  19.         System.out.println("Array: " + numbers);
  20.         System.out.println("Size: " + numbers.size());
  21.  
  22.         System.out.println("------------------------------");
  23.  
  24.         //POINT 3) Add value to the right place in arrayList
  25.  
  26.         System.out.println("List before replacing current index with some other value: ");
  27.         System.out.println("Array: " + numbers);
  28.         System.out.println("Size: " + numbers.size());
  29.  
  30.         numbers.set(3 , 8);
  31.  
  32.         System.out.println("List after replacing current index (3) with some other value (8) : ");
  33.         System.out.println("Array: " + numbers);
  34.         System.out.println("Size: " + numbers.size());
  35.  
  36.         System.out.println("------------------------------");
  37.  
  38.         //POINT 4) Remove element by index from arrayList
  39.         System.out.println("List before removing current index (5) : ");
  40.         System.out.println("Array: " + numbers);
  41.         System.out.println("Size: " + numbers.size());
  42.  
  43.         numbers.remove(4);
  44.  
  45.         System.out.println("List after removing current index (5) : ");
  46.         System.out.println("Array: " + numbers);
  47.         System.out.println("Size: " + numbers.size());
  48.  
  49.         System.out.println("------------------------------");
  50.  
  51.         //POINT 5) Remove element by its value
  52.         System.out.println("List before removing element by its value : ");
  53.         System.out.println("Array: " + numbers);
  54.         System.out.println("Size: " + numbers.size());
  55.  
  56.         numbers.remove(new Integer(1));
  57.  
  58.         System.out.println("List after removing element by its value : ");
  59.         System.out.println("Array: " + numbers);
  60.         System.out.println("Size: " + numbers.size());
  61.  
  62.         System.out.println("--------------END---------------");
  63.  
  64.     }