Length Sintaxis in Java

Posted on 2004-11-06
Last Modified: 2012-08-14
What is the sintaxis for the function lenght in Java, could you pls provide an example. What I really need is to determine how many characters are in variable.Tks in advance
Question by:maerskssc
    LVL 3

    Accepted Solution

    Hi maerskssc,

    on arrays it si:
    int intArray[] = new int[8];
    intArray.length;        // this returns the number of array-elements

    on a string it is:
    String s = "test";
    s.length();         // this return 4 which is the length of the string

    LVL 13

    Expert Comment

    Hi maerskssc,

    import java.lang.reflection;

    do this function

    public void displayClassFieldName(Class theClass)
        Field[] fields = theClass.getDeclaredFields();
        for(int i = 0; i < fields.length ; i++ )
          String fieldName = fields[i].getName();


    call like this:


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now