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);

devx-admin

Share the Post: