• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing a String to a String in an Array

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 67
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may consider using a set:

 
Brandon Golway
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That worked, thanks Mike!
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My pleasure Brandon. Good luck and don't hesitate to ask questions!
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aha then I misinterpreted it. But my post still stands.
reply
    Bookmark Topic Watch Topic
  • New Topic