473,405 Members | 2,415 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,405 software developers and data experts.

ArrayList question

Hi all,

Is it possible to create an ArrayList which will accept any object from the number class? i have tried something like:

ArrayList<? extends Number> userList = new ArrayList<? extends Numer>();

i get this as error: Cannot instantiate the type ArrayList<? extends Number>

and this doesn't work either:

ArrayList<T> userList = new ArrayList<T>();

and the error here is that T can not be initiated as a type.

I know that by accepting an object of any type will cause exceptions to be thrown like trying to perform numerical operations on string objects, for example, so i need to take that into consideration. again, the question here is: is there any way to initialize an ArrayList that will accept any type from the Number class in java to perform numerical calculations on?

thanks
Apr 9 '09 #1
2 3577
JosAH
11,448 Expert 8TB
It's a bit tricky but very well explained in the first half of this link. That wildcard extension mechanism baffles me too now and then.

kind regards,

Jos
Apr 10 '09 #2
Thank you Jos, your help is greatly appreciated!
Apr 12 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
3
by: george r smith | last post by:
I am trying to create an arrayList that contains multiple arrayLists. My code attempt is below. The question I have is how can I get away from creating another pAttribute list than can be added to...
4
by: NuCoder | last post by:
How can i get an item out of an ArrayList to write to a file? I want to add the items to a collection to write them to a file.
1
by: MM | last post by:
How do you reference a Hashtable in an ArrayList? ArrayList al = new Arraylist(); al.Add(new Hashtable()); now howto add/access hashtable entries? thanks, matthew.
8
by: ttan | last post by:
//I had a class public class PERSON { PERSON(string LName, string FName, string age) { m_last = LName; m_first = FName; m_age = age; }
2
by: keys4worship | last post by:
I am populating an arraylist from a text file on my PC. I am using this information with C# to perform actions against a PCOM session. A for loop handles the actions to perform. If for some reason...
1
by: Roshawn Dawson | last post by:
Hi, I have an arraylist that contains unknown object types. How would I go about creating a new string with only the values in the string objects contained within the arraylist? Thx
3
by: Jerry West | last post by:
I have an ArrayList of DirectoryInfo structures. As I'm certain you know, each DirectoryInfo structure has a property called FullName. I'm trying to get at the fullname property for the first...
10
by: writeallnight | last post by:
I can't seem to "disconnect" a "rebuilt" ArrayList of objects from it's source AL; I thought I understood the rules on copying AL Data objects vs. the "clone" Method (and it's simply being a...
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: 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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
tracyyun
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...
0
isladogs
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...

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.