Posts

ArrayList

Features Initialise w ith initial capacity.              List<Integer> list = new ArrayList<>(100);            But this will help if you have idea about initial size of ArrayList Initialise w ithout initial capacity            List<Integer> list = new ArrayList<>();            Default it is initialised with size 10 Index based search             list.get(13); Can be used only with Objects/Wrapper classes and not with primitives.            This is valid -  List<Integer> list = new ArrayList<>(100);           This is invalid -  List<int> list = new ArrayList<>(100); How to iterate ArrayList? For loop List<Integer> list = new ArrayList<>() ; for ( int i = 0 ; i<list....

Java-Collection Framework

Image
Before java 1.2 we had only Arrays, Vectors and HashTables. You don't have to know about vectors and Hashtable now.  By now you know that working with Arrays is not that easy due to its fix size. Vector and HashTable had its own challenges. Due to this it was difficult for programmers to write complex algorithm.  Then Java launched Collection framework in 1.2 version. Collecitions frameworks has mainly 2 interfaces. Collection and Map, below is complete hierarchy of collections framework.  List : List can have duplicate elements and elements are ordered. We will be covering ArrayList in detail and brief overview of LinkedList Set : It doesn't allow duplicate element. We will covering HashSet in detail and brief overview of TreeSet and LinkedHashSet.  Queue : Typically ordered in FIFO. We won't be covering this interface Map : It's Key value pair. We can't have duplicate keys in Map. We will be covering HashMap in detail and brief ove...

Java Variable

Java has 8 primitive datatypes: byte, short, int, long, float, double, boolean and char These primitives types have default values