473,387 Members | 3,810 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,387 software developers and data experts.

reverse a collection

i have a colleciton that i need to reverse. Array has a reverse method. Is
their any direct way to transfer the items in the collection to an array or
arraylist, reverse the array and transfer back them to the collection.
Or looping through each element is the only option.

TIA
nafri
Nov 21 '05 #1
2 4352
Nafri,
It depends on what kind of collection you have, ArrayList has a ToArray
method, if your collection is based on ArrayList either directly or
indirectly (CollectionBase) you can leverage this method.

ArrayList has AddRange & a constructor that accepts a collection, you could
indirectly (CollectionBase) leverage this methods to return the array back
to the collection.

If your collection is not based directly or indirectly on ArrayList, or have
similar methods, then you are correct, looping may be your only option.

Some collections, such as Hashtable, do not support he concept of an order,
so reversing them do not make sense per se.
Hope this helps
Jay

"nafri" <sp****@spam.net> wrote in message
news:F3**********************************@microsof t.com...
i have a colleciton that i need to reverse. Array has a reverse method. Is
their any direct way to transfer the items in the collection to an array
or
arraylist, reverse the array and transfer back them to the collection.
Or looping through each element is the only option.

TIA
nafri

Nov 21 '05 #2
You can but you need to watch out array is the collection of the same data
type.

chanmm

"nafri" <sp****@spam.net> wrote in message
news:F3**********************************@microsof t.com...
i have a colleciton that i need to reverse. Array has a reverse method. Is
their any direct way to transfer the items in the collection to an array
or
arraylist, reverse the array and transfer back them to the collection.
Or looping through each element is the only option.

TIA
nafri

Nov 21 '05 #3

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

Similar topics

14
by: Erik Andersson | last post by:
Hi! I need to read a file (line-by-line) in reverse order, without reading the whole file into memory first. Is there an easy way of doing this? As in, is there a PHP function I could use? ...
35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
14
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
4
by: Sagaert Johan | last post by:
Hi Is this something for C# V2 ? Queue msgqueue =new Queue (); //fill some data in the queue here with this function & keep only the last 5 events void addtolog(string msg) {
15
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
11
by: Boni | last post by:
Dear all, following code iterates thru the hash table. Dim _Enumerator As IDictionaryEnumerator = _myhashtable.GetEnumerator While _Enumerator.MoveNext() ....
15
by: Fabio Cannizzo | last post by:
Is it possible to do something similar to the STL iterators, i.e. to execute a foreach loop in reverse order? Thanks, Fabio
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.