View RSS Feed

Recent Blogs Posts

  1. Use Lists instead Arrays in Generics

    by , 11-29-2011 at 11:20 PM
    Generics were added to java in release 1.5. It allows you to avoid needing to cast objects as they are read from a collection. Instead you tell the compiler what types of objects that you want to hold in the collection. Often it is difficult to know which generic to use when you have two or more who seem to be able to complete the same function. Consider the choice between whether to use a list or an array. Now a key thing to remember is that arrays are covariant and know and enforce their element ...
  2. Using Arrays in Java

    by , 11-08-2011 at 06:24 PM (My Java Tips)
    Arrays are simply a sequence of memory locations for storing data. The index of an array starts from zero. We have to mention the size of an array while declaring it. Once declared, we cannot change the size at any stage.

    While working with arrays, you will encounter ArrayIndexOutOfBoundsException. This exception is raised if you try to access an element from the array with negative index, or with index greater than the length of index.

    Sorting an array is easy in Java ...
    Tags: array, size fixed Add / Edit Tags
    Categories
    Java SE
  3. ArrayStoreException

    by , 05-24-2011 at 01:48 PM (My Java Tips)
    java.lang.ArrayStoreException is a runtimeException and is thrown when we try to store wrong type of object into an array of objects.

    Constructors:

    Java Code:
    ArrayStoreException()
    ArrayStoreException(String s)
    For example: Storing an Integer object in a Strign array will cause this exception.

    Java Code:
    Object x[] = new String[3];
    x[0] = new Integer(0);
    Since its a runtime exception, compiler won't ...
    Categories
    Java SE