| Author |
easy array question
|
Alex Hank
Greenhorn
Joined: Apr 27, 2005
Posts: 16
|
|
I have some simple code that blows up if the string array is empty. I need an if statement that will not execute the code if the array is empty. int numDir = 0; String [] selfiles = request.getParameterValues("selfile"); for(int i = 0; i < selfiles.length; i++){ if(selfiles[i].indexOf(".") == -1 ){numDir++;} }//ELEMENTS WITHOUT "." ARE NOT FOLDERS I need an if statement that will not run the for loop if the array selfiles is empty. thanks Alex
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
I'm assuming you mean null. That for loop shouldn't blow up if you have a zero length array. [ June 21, 2005: Message edited by: Ben Souther ]
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Tim Baker
Ranch Hand
Joined: Oct 04, 2003
Posts: 541
|
|
A look at the code suggests that it should cope fine when the array is empty, ie a zero sized array. However I suspect your problem is when the array variable is null. So the check you would want is Someone will also probably tell you this was not the right place to post it, as it has little to do with JSP and is more of a java beginners question.
|
Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
|
Moved to Java in General(beginner).
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: easy array question
|
|
|