Hi I am new to this language, and still don't understand most of the
concepts, I am trying to sort an arraylist by alphabet, I belive i
need to use the IComparer interface, but have no idea how this works?
Does anyone have a sample of how i can sort my arraylist of words.
Also how is an arraylist iterated over and is it possible to obtain a
count of the number of occurences of each owrd in the array list? Many
thanks. 2 3868
Just call the Sort() method of your ArrayList. It will use the IComparable
implementation of the items in the list, in this case, strings. These
should sort as you expect; you don't have to do Sort(IComparer) unless have
some special requirements.
--Bob
"steve smith" <bo**********@h otmail.com> wrote in message
news:4b******** *************** ***@posting.goo gle.com... Hi I am new to this language, and still don't understand most of the concepts, I am trying to sort an arraylist by alphabet, I belive i need to use the IComparer interface, but have no idea how this works? Does anyone have a sample of how i can sort my arraylist of words. Also how is an arraylist iterated over and is it possible to obtain a count of the number of occurences of each owrd in the array list? Many thanks.
Steve,
Missed the 2nd parts of your question.
You can iterate over an ArrayList of strings "al" in the following ways:
// for loop
for (int i = 0;i < al.Length;i++) {
string s = (string)al[i];
// do stuff with s
}
// foreach loop
foreach (string s in al) {
// do stuff with s
}
// IEnumerator interface
IEnumerator alEnumerator = al.GetEnumerato r();
while (alEnumerator.M oveNext()) {
string s = (string)alEnume rator.Current;
// do stuff with s
}
To obtain a count of occurences you'll have to write your own routine, along
the lines of:
int Occurs(string strSearch,Array List al) {
int intCount = 0;
foreach (string s in al) {
if (s == strSearch) {
intCount++;
}
}
return intCount;
}
--Bob
"steve smith" <bo**********@h otmail.com> wrote in message
news:4b******** *************** ***@posting.goo gle.com... Hi I am new to this language, and still don't understand most of the concepts, I am trying to sort an arraylist by alphabet, I belive i need to use the IComparer interface, but have no idea how this works? Does anyone have a sample of how i can sort my arraylist of words. Also how is an arraylist iterated over and is it possible to obtain a count of the number of occurences of each owrd in the array list? Many thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: D. Roshani |
last post by:
Hello !
I wonder if any one can help me to create a cosomize sorting order (as Macro or added small program
in c++ or c# which does this work) in a Access Database contaning one table only words encoded in
ISO-8859-1
A a B b C c D d E e É é F f G g H h I i Í í J j
1 2 3 4 5 6 7 8 9 10 11 12
Jh jh K k L l ll M m N n O o P p Q q R r rr S s...
|
by: jarkkotv |
last post by:
Hi everyone!
I'm having a little problem when sorting the ArrayList and I was
wondering if there is a .NET guru who can help me out :)
I'm trying to sort ArrayList alphabetically in ASP.Net -page using the
ArrayList.Sort(), but I not getting the results sorted properly.
I'm having problems especially with the scandic characters although
CurrentCulture is set to Finnish, which should handle these charcters
|
by: Bob Weiner |
last post by:
What I want to be able to do is create an indexer that can index into an
ArrayList filled with objects of my own type. I have the following class
structure:
----------------------------------------------
class PropertyList : ArrayList {
public enum SortOrder { }
public object this { // cannot figure this one
t }
|
by: steve smith |
last post by:
Hi I'm still having some problems getting my head round this language.
A couple of things don't seem to work for me. First I am trying to
obtan a count of the number of words in a sting, so am using the split
function with ' ', but how do i get it to take into account
punctuation marks such as ',',',' etc?
Also I am then trying to add contents of an array of strings to an
arraylist, but only if the string isn't already there. I was using...
|
by: Jack Addington |
last post by:
I want to scroll through the alphabet in order to scroll some data to the
closest name that starts with a letter. If the user hits the H button then
it should scroll to the letter closest to H. If no one exists with H, then
go to I, etc. If its near the end, say 'V', and the last person is a 'T'
then it should work its way back up the alphabet. I was trying to loop as
if the Char's were ints but I am having problems
I have buttons...
| |
by: jtfaulk |
last post by:
Re: ArrayList, Sort, Menu, IComparer, Object, multidemensional
I have a multi-dimensional arraylist, and I would like to sort one
level of it but not all. The multi-dimensional arraylist represents my
menu system, and I would like to sort the third level menu items only
and not the first two.
So, I've been trying to use some of the suggestions I've found here
about sorting. Mainly, I've created a comparison interface.
|
by: Justin |
last post by:
Ok, I give up. I can't seem to construct a decent (productive) way of
sorting my arraylist.
I have a structure of two elements:
Structure TabStructure
Dim TabName As String
Dim FullFilePath As String
End Structure
|
by: almurph |
last post by:
H ieveryone,
Can you help me please? I am trying to sort a hashtable but get the
error: "Cannot implicity convert type void to
System.Collections.ArrayList"
I am doing the following:
****BEGIN CODE****
|
by: almurph |
last post by:
H ieveryone,
Can you help me please? I am trying to sort a hashtable but get the
error: "Cannot implicity convert type void to
System.Collections.ArrayList"
I am doing the following:
****BEGIN CODE****
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |