ArrayList

  • Thread starter Thread starter Sehboo
  • Start date Start date
S

Sehboo

All,

I have an arraylist in which I need to add a string, but before I add
I need to make sure that the same string is not already there. Yes, I
could run a for loop to check all the items but I could have thousands
of items and I don't want to run the loop everytime (CPU usage got
upto 100%)....what can I do...to make a faster lookup?

I don't have to use ArrayList...I could pretty much use anything which
will hold the list of strings...

Thanks
 
All,

I have an arraylist in which I need to add a string, but before I add
I need to make sure that the same string is not already there. Yes, I
could run a for loop to check all the items but I could have thousands
of items and I don't want to run the loop everytime (CPU usage got
upto 100%)....what can I do...to make a faster lookup?

I don't have to use ArrayList...I could pretty much use anything which
will hold the list of strings...

Thanks

Do you need the search to be case sensitive or not? If you need it case
sensitive, then you can simply do

If myArraList.Contains("Skunk") Then
....
Else
End If

Though, you may want to use a StringCollection from
System.Collections.Specialized...

Actually, (sorry, this is a stream of consciousness thing :) - if you
need case insensitve look up that is pretty fast, you might want to use
StringDictionary from System.Collections.Specialized. Then you can add
your string as both a key and a value...

sc.Add(MyString, MyString)

....


If sc.ContainsKey(MyString) Then
Else
End If

Anyway, that's a couple of ideas for you :)
 
One more question...

How do I go through the entire StringDictionay list?
it seems like I can't run the for loop.

Thanks
 
Back
Top