Results 1 to 5 of 5
  1. #1
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    114
    Rep Power
    0

    Default Check the existence of a parameter.

    How can I check the existence of a parameter in Java and if it doesn't exists, I want to assign a default value?

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    364
    Rep Power
    5

    Default Re: Check the existence of a parameter.

    I'm assuming you mean a parameter passed to a method? You just have to check if the argument is null:

    Java Code:
    private void doSomething(String firstName, String lastName) {
       if(firstName == null) {
           //set default
       }
      .....
    }

  3. #3
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    114
    Rep Power
    0

    Default Re: Check the existence of a parameter.

    Quote Originally Posted by sehudson View Post
    I'm assuming you mean a parameter passed to a method? You just have to check if the argument is null:

    Java Code:
    private void doSomething(String firstName, String lastName) {
       if(firstName == null) {
           //set default
       }
      .....
    }
    Thanks for your reply but I meant to say something like this :
    The cfparam tag used in coldfusion.

    https://wikidocs.adobe.com/wiki/disp...sionen/cfparam

  4. #4
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: Check the existence of a parameter.

    His code does the same thing. If there is no value assigned to the parameter, it will give it the default value of you choosing.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Check the existence of a parameter.

    The value is given to a variable and that variable can be used as an arg to a method. The using of a variable as an arg has nothing to do with what value it has.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: 05-07-2013, 11:43 AM
  2. Replies: 2
    Last Post: 02-05-2013, 04:35 PM
  3. Replies: 5
    Last Post: 10-17-2012, 11:07 AM
  4. Replies: 1
    Last Post: 08-02-2009, 12:52 PM
  5. Verifying existence of a table in a db
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •