473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ArrayList

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
Nov 20 '05 #1
4 1412
Hi,

Take a look at the hash table.
http://msdn.microsoft.com/library/de...classtopic.asp
Ken
-------------------
"Sehboo" <ma*********@hotmail.com> wrote in message
news:7b**************************@posting.google.c om...
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

Nov 20 '05 #2
On 2004-02-19, Sehboo <ma*********@hotmail.com> wrote:
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 :)
--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
Facts are the enemy of truth.
-- Don Quixote
Nov 20 '05 #3
Thanks Tom,

That has faster lookup then ArrayList.

Tom Shelton <to*@mtogden.com> wrote in message news:<Ot**************@TK2MSFTNGP10.phx.gbl>...
On 2004-02-19, Sehboo <ma*********@hotmail.com> wrote:
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 :)

Nov 20 '05 #4
One more question...

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

Thanks
ma*********@hotmail.com (Sehboo) wrote in message news:<7b**************************@posting.google. com>...
Thanks Tom,

That has faster lookup then ArrayList.

Tom Shelton <to*@mtogden.com> wrote in message news:<Ot**************@TK2MSFTNGP10.phx.gbl>...
On 2004-02-19, Sehboo <ma*********@hotmail.com> wrote:
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 :)

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
6
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow =...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
3
by: Christopher H | last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as value, but I still can't get my program to work like I want it to. Simple example: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.