473,385 Members | 1,940 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,385 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 1416
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: ...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.