The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by Hiran on October 31, 2001 at 2:17 PM

Sorry...the other post was hard to read, so i cleaned it up a bit.

  1. The second case sounds like what you want (sounds like you want an unitialized String), but you don't need to explicitly initialize it to null, since that is the default behavior.

There's a problem though. Here's my code:

public String getNextLocName(String direction)
{ String nextLocName;
for (int i=0; i { if (directions[i].equalsIgnoreCase(direction))
{ nextLocName = assocLocs[i];
return nextLocName;

When I try to run it, an error comes up saying that nextLocName might not be initialized. So do I have to put String nextLocName = null;? (In case you're wondering, the method that calls this method takes the string that's returned and runs it through a for loop checking to see if nextLocName is equal to null or not).


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us