aspose file tools*
The moose likes Beginning Java and the fly likes Slightly confused with object value = null. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Slightly confused with object value = null." Watch "Slightly confused with object value = null." New topic
Author

Slightly confused with object value = null.

David Ward
Greenhorn

Joined: Oct 31, 2011
Posts: 22
Hi again folks! Just a quick couple of questions this time.

If I have initialized a load of Strings

I then change the string later if the conditions are true,


So, m9 becomes the module and room. However, later on m12 fails the IF and returns null instead. I kinda hoped that the first code where I initialized all the strings that I could force them to be "".

Anyway I can do an to cover all of my IF statements? Rather than one for each IF? Because I need to test for each hour period and day. Hope that makes sense. ;p
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
you haven't initialized all the strings except m17
David Ward
Greenhorn

Joined: Oct 31, 2011
Posts: 22
Yeah I thought that but I'm sure I saw my tutor use something similar? shorthand to initialize them all?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

You can use the shorthand to avoid specifying each variable as a static String, but you still need to give them separate initial values (unless you're happy with the default).
David Ward
Greenhorn

Joined: Oct 31, 2011
Posts: 22
Thanks guys! Feel a bit foolish now! lol!

But of curiosity , if i were to keep each String as null until it passes the IF test, would I be able to catch all nulls and return ""?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
You can initialise all your strings like this

or you could use an array of strings


Joanne
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Even better :-p
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
And with lists?

David Ward
Greenhorn

Joined: Oct 31, 2011
Posts: 22
Thanks very much guys! Great info!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Slightly confused with object value = null.