devxlogo

Array Length

Array Length

Question:
How do I know the size of the array returned by File.list() so I don’t get the message ArrayIndexOutOfBoundsException when printing the local directory content in the screen?

Answer:
All arrays have an intrinsic member variablecalled length. To get the list length you would do the following:

File list;list = directory.list();System.out.println("Numbr of Files is: " + list.length);
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist