Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Length Sintaxis in Java

Posted on 2004-11-06
2
Medium Priority
?
347 Views
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
0
Comment
Question by:maerskssc
2 Comments
 
LVL 3

Accepted Solution

by:
nesnemis earned 2000 total points
ID: 12513134
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

nesnemis
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12513158
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();
      System.out.println(fieldName.length());
    }

}

call like this:
displayClassFieldName(myObject.getClass())


Cheers!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

564 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