Array vs ArrayList in Java:
Array - Fixed Size, Same Data Types only
HashTable - Syncronized, will not allow NULL key/value.
- put, get
HashMap - UnSyncronized, will allow NULL key/value (so maybe good performance than HashTable)
- put, get
HashSet - Will allow duplicate values
- add, contains, get
Array - Fixed Size, Same Data Types only
- int[] myArr = new int[10];
- myArr[0] = 10;
- System.out.println( myArr[0] );
- System.out.println( myArr.length );
- ArrayList<String> myList = new ArrayList<String>();
- myList.add("abcd");
- myList.add(10); //Adds in end of list because index not mentioned.
- System.out.println( myList.get(0) );//Lot of methods are there here.
- add(index, Value);
- addAll(collection);
- clear()
- contains(value)
- indexOf(value)
- get(index)
- isEmpty()
- lastIndexOf(value)
- set(index, value) //Replace the value
- size()
- toArray()
- iterator() // One-Directional, only access
- listIterator() //Bi-Dierectional, allows modification
HashTable - Syncronized, will not allow NULL key/value.
- put, get
HashMap - UnSyncronized, will allow NULL key/value (so maybe good performance than HashTable)
- put, get
HashSet - Will allow duplicate values
- add, contains, get
Comments
Post a Comment