Results 1 to 9 of 9
Thread: Check for empty arguments
- 04-17-2009, 09:23 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 7
- Rep Power
- 0
- 04-17-2009, 09:43 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
.equals is a method not a field. How do you use a method?
Edit: You may also want to check, however, whether or not args[1] even exists, and whether or not it might be null, to avoid that statement itself throwing a couple of possible exceptions.
- 04-17-2009, 10:14 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 7
- Rep Power
- 0
Can you please send me some tutorials regarding it
- 04-17-2009, 10:17 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Regarding what?
How to use a method?
How to get the length of an array?
How to use an if statement?
Those are all that are involved.
- 04-17-2009, 10:47 AM #5
Hi,
equals is a method .U have to use like this below.
if(args[1].equals(""){
//statement
}
else {
//statement
}
But without aupplying args[1] value if u try to use the above code then u will get "ArrayIndexOutOfBoundsException"
- 04-17-2009, 11:55 AM #6
Member
- Join Date
- Apr 2009
- Posts
- 7
- Rep Power
- 0
I have to pass two arguments.
If the second argument is empty it should not print any exception and it should return "";
- 04-17-2009, 12:02 PM #7
Hi,
be specific with ur question.can u please send the code so that i can answer?
- 04-17-2009, 01:23 PM #8
Member
- Join Date
- Apr 2009
- Posts
- 7
- Rep Power
- 0
When I run the java program with one argument and if second argument is not passed it should return "" without giving an exception
If the second argument is present then I have to assign as variable string as filename else I have to assign the value to ""
;
- 04-17-2009, 01:30 PM #9
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Like I said, check that the length of the "args" array is at least 2 using length and an if statement, then use the equals method properly. Check your study notes and/or prior/example programs from your class to see how to use a method.
Edit: Also, if the length of the array is not 2 or more, than, obviously, there is no second argument, so no reason to even attempt to use the equals method. And, if it is there, it is obviously not "empty" although it could be composed of all spaces by entering " " on the command line. If that needs to be checked for, then you are going to have to use the trim method and then the equals method (or better length method checking for more than 0) in succession.Last edited by masijade; 04-17-2009 at 01:47 PM.
Similar Threads
-
empty arrays.
By circuspeanuts in forum New To JavaReplies: 11Last Post: 04-06-2009, 07:08 PM -
KeyBindings Empty Key?
By Unome in forum Java AppletsReplies: 1Last Post: 10-24-2008, 07:28 PM -
Empty ResultSet
By Java Tip in forum Java TipReplies: 0Last Post: 02-09-2008, 08:36 PM -
Not Empty check of texboxes using javascript
By Anju Jose in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-09-2008, 12:04 PM -
BufferedReader empty
By Peter in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 06:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks