• Post Reply Bookmark Topic Watch Topic
  • New Topic

hugeString.contains()  RSS feed

 
Ryan Waggoner
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am just doing a quick piece of validation where I am taking a piece of info (account number) and seeing if it exists in a static set of account numbers (a string that looks like 123, 321, 132, 312 etc.)

The string has at least 200 different account numbers in it, and looks kind of ugly. I thought about doing the validation against the database, or maybe creating a class whose only purpose is to provide this validation.

But I want to make sure it's and memory friendly as possible, and both of those options seem they would take more of it.


Any advice?

Thanks!
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to have those 200 numbers somewhere, right? In memory seems like the most convenient place to me. And there's only 200 of them.

Were they already in a string to begin with? Because if you're just jamming them into the string so you can search it, I wouldn't do that. I would put them into a Set and search that. Or you could validate them by looking them up in the database, too. That would be okay if your program was doing a lot of other things besides validating numbers. Or even if that was the only thing it was doing, but it wasn't doing much of it.

Here's what I think you should do: Do the simplest thing which will work. You have a very small problem and it isn't worth spending a lot of time on it. If what you do turns out not to work well later on, then change it.
 
Ryan Waggoner
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,
I appreciate the advice, and quick response!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!