what does length represents in the following code snippet: int a[]={10,20,30}; System.out.println(a

Vikash Verma

Vikash Verma

@vikash-verma-jF0MOy Oct 26, 2024
sorry the last line of code is





System.out.println(a.length);

what exactly length is...😎

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Kaustubh Katdare

    Kaustubh Katdare

    @thebigk Jun 19, 2012

    Please post the full code in the post, title is just a title.
  • Dancer_Engineer

    Dancer_Engineer

    @dancer-engineer-EJ8rGI Jun 19, 2012

    If this is your code:
    int a[] = {10,20,30};
    System.out.println(a.length);
    Here 'a.length' gives the length of the array 'a'.
  • Vikash Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 19, 2012

    I mean to find array length , we use arrayname.length .
    What is this length variable, where it is generated, is arrayname a class,. . .
  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jun 19, 2012

    I tried to find out source code for array but didn't got it. There is array class in java.lang.reflect package but that is different and similar to array functionality.

    Well answer is Array is not a class. Its a reference type. There are three reference type in java class, interface and array
    it is built-in JVM part and array.length is defined as
    public final <variable> length. as array length is constant which stores length of array.
  • Dancer_Engineer

    Dancer_Engineer

    @dancer-engineer-EJ8rGI Jun 19, 2012

    #-Link-Snipped-#, you may take a look at these links:
    <a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html" target="_blank" rel="nofollow noopener noreferrer">Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)</a>
    <a href="https://www.roseindia.net/java/master-java/Reference-Data-Types.shtml" target="_blank" rel="nofollow noopener noreferrer">Reference Data Types</a>
  • suraz

    suraz

    @suraz-mouLU5 Jun 19, 2012

    #-Link-Snipped-#
    check this out
  • Vikash Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 19, 2012

    #-Link-Snipped-# you are right...😎