Core Java with OCJP/SCJP: Language Fundamentals Part-9 || Arrays Part-4

Java

Video is ready, Click Here to View ×


https://youtu.be/HYAosZptldA?list=PLd3UqWTnYXOkWWJd8flj3echGYm3y5dXo

25 thoughts on “Core Java with OCJP/SCJP: Language Fundamentals Part-9 || Arrays Part-4

  1. Sir args=argh means argh will also point to array object which is referenced by args….right to left assignment operator will work…but in your explaination it is opposite why

  2. package learning;
    public class MultiDimension {
    public static void main(String[] args) {
    final String ar[][][] = {{{"1","2"},{"3","4","5"}},{{"6","7","8"}},{{"9","10"},{"11"},{"12","13","14","15"}}};//new String[1][3][2][2];
    //Integer integerAr[][] = {{1},{2}};
    //byte byteAr[][] = {{1},{2}};
    //int[] intAr = (int[])byteAr;
    recPrintArray(ar);
    }

    public static void recPrintArray(Object ar) {
    recPrintArray(ar,getDimensions(ar));
    }

    public static void recPrintArray(Object ar,int noOfDimension) {
    for (Object obj:(Object[]) ar) {
    if (noOfDimension > 1)
    recPrintArray(obj, noOfDimension – 1);
    else {
    String dataType = obj.getClass().getName();
    switch (dataType) {
    case "[B":
    printAll((byte[]) obj);
    break;
    case "[S":
    printAll((short[]) obj);
    break;
    case "[I":
    printAll((int[]) obj);
    break;
    case "[J":
    printAll((long[]) obj);
    break;
    case "[F":
    printAll((float[]) obj);
    break;
    case "[D":
    printAll((double[]) obj);
    break;
    case "[Z":
    printAll((boolean[]) obj);
    break;
    case "[C":
    printAll((char[]) obj);
    default:
    printAll((Object[]) obj);
    }
    //System.out.print("> " + obj + " ");
    }
    }
    }

    public static void printAll(byte[] ar) {
    for (byte val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(short[] ar) {
    for (short val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(int[] ar) {
    for (int val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(long[] ar) {
    for (long val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(float[] ar) {
    for (float val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(double[] ar) {
    for (double val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(char[] ar) {
    for (char val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(boolean[] ar) {
    for (boolean val: ar)
    System.out.print(">" + val + " ");
    }

    public static void printAll(Object[] ar) {
    for (Object val: ar)
    System.out.print(">" + val + " ");
    }
    /*return the number of dimension of an array
    * takes any reference type as argument
    * using the Object class getClass() and Class getName() methods
    */
    public static int getDimensions(Object intAr) {
    return intAr.getClass().getName().lastIndexOf("[");
    }
    }

  3. I have read in a site it says the size of an array must be specified by an int value and not long or short!
    But in video you mentioned that int byte char short can be used but not others..
    Confused!

  4. Sir …you are "the best "in java as far as concern to teaching.I have a problem understanding the concept.At 23:13 we get compile time error but in part -7 at 14:57 we have assign 2 dimensional array to 1 dimensional array without any problem ….how ? would be great if you help me.Thanks a million.

  5. Sir AFTER the CASE 3 example, about command line argument example (33:14)it is not giving any runtime exception as Array out of bounce exception… It is printing the same arguments. If I use Sopln(args.[i+1]); it is giving that error

  6. sir in the last question a[1]= new int [2] only one object is getting creates instead of two , so the the total number of objects would become 11 and object elligible for gc would become 7

Leave a Reply

Your email address will not be published. Required fields are marked *