| Author |
Comparing a String to a String in an Array
|
Brandon Golway
Greenhorn
Joined: Oct 19, 2010
Posts: 23
|
|
I converted a game that I wrote in Python to java (since Im currently learning it in my college class) and I cant figure out how to compare a string to a string in an array without doing a lot of coding. All I basically want is if the player finds a weapon it gets added to their weapon array, then when you call the inventory function it will list the players weapons.
Heres the simpliest excerpt I could make
the first line of ListWeapons() throws a NullPointerException
|
 |
Kevin Workman
Ranch Hand
Joined: Sep 28, 2010
Posts: 151
|
|
Stupid question- Do you actually ever call AddWeapon (which should be addWeapon, by the way) with each parameter?
Posting an SSCCE would help clear up any more confusion about what you're doing, which would help you get assistance faster.
|
 |
Mike Peters
Ranch Hand
Joined: Oct 10, 2009
Posts: 67
|
|
You may consider using a set:
|
Mike Peters
|
 |
Brandon Golway
Greenhorn
Joined: Oct 19, 2010
Posts: 23
|
|
|
That worked, thanks Mike!
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
Kevin Workman wrote:Stupid question
There are no stupid questions only stupid answers. Remember that we'll had to learn Java at one point.
|
 |
Mike Peters
Ranch Hand
Joined: Oct 10, 2009
Posts: 67
|
|
|
My pleasure Brandon. Good luck and don't hesitate to ask questions!
|
 |
Kevin Workman
Ranch Hand
Joined: Sep 28, 2010
Posts: 151
|
|
Wouter Oet wrote:
Kevin Workman wrote:Stupid question
There are no stupid questions only stupid answers. Remember that we'll had to learn Java at one point.
I was saying my question was stupid, not the OP's. It's easy to miss the "obvious" stuff when you've been staring at the same code for days, so sometimes all it takes is somebody else asking a stupid question to help you along.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Aha then I misinterpreted it. But my post still stands.
|
 |
 |
|
|
subject: Comparing a String to a String in an Array
|
|
|