среда, 24 февраля 2016 г.

Create Array vs ArrayList vs Hashmap

Array vs Arraylist differences

  • Array has fixed size Vs Arraylist has flexible size


One option how to create array and specify values :

int[] myIntArray = new int[]{1,2,3}; // Initialization and values 
String[] myStringArray = new String[]{"a","b","c"}

Second 2 options will give you error "Array constants can only be used in initializers". So please dont use them.
 private int[] myNumbers; 
myNumbers= new int[3]; //Initialization
myNumbers={1,2,3};

int[] myIntArray = new int[3]; 

int[] myIntArray = {1,2,3}; 

ArrayList
ArrayList<Class> myList = new ArrayList<Class>();

Комментариев нет:

Отправить комментарий