This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
i implemented arraylists and they work with rs.getString, like in:
lotnum.add(num, rs.getString("lotnum"));
but if i do this: lotnum.add(num, rs.getInt("lotnum"));
it outputs an error saying cannot resolve symbol method add(int,int);
Kj Reddy
Ranch Hand
Joined: Sep 20, 2003
Posts: 1697
posted
0
Originally posted by shuini gustav: i implemented arraylists and they work with rs.getString, like in:
lotnum.add(num, rs.getString("lotnum"));
but if i do this: lotnum.add(num, rs.getInt("lotnum"));
it outputs an error saying cannot resolve symbol method add(int,int);
I assume rs is Resultset object, lotnum is Arraylist.
You can add only objects to ArrayList. But Resultset.getInt() will return you int primitive data type. So lotnum.add(num, rs.getInt("lotnum")); do not work.
You can try lotnum.add(num, new Integer(rs.getInt("lotnum")));
Bernard Sigmund Gustav
Ranch Hand
Joined: Dec 20, 2005
Posts: 170
posted
0
ok. but when i tried to convert it into an array with .toArray(), it says cannot resolve symbol method toArray(int[]);
Kj Reddy
Ranch Hand
Joined: Sep 20, 2003
Posts: 1697
posted
0
Originally posted by shuini gustav: ok. but when i tried to convert it into an array with .toArray(), it says cannot resolve symbol method toArray(int[]);
Can you provide more details what you trying?
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Integer[] array = new Integer[lotnum.size()]; lotnum.toArray(array);
There is no emoticon for what I am feeling!
Bernard Sigmund Gustav
Ranch Hand
Joined: Dec 20, 2005
Posts: 170
posted
0
Originally posted by Jeff Albertson: Integer[] array = new Integer[lotnum.size()]; lotnum.toArray(array);
thanks.
but what is the difference of Integer and int? i mean i know the first one is an object and the second one is a primitive data type but why does ArrayList need objects and not primitive data types?
My database fields from where they are retrieved are of type int and not Integer
Ernest Friedman-Hill
author and iconoclast
Marshal
but what is the difference of Integer and int? i mean i know the first one is an object and the second one is a primitive data type but why does ArrayList need objects and not primitive data types?
My database fields from where they are retrieved are of type int and not Integer
1. You got it. The difference between java.lang.Integer and int is that the first is a class and the second a primitive type.
2. ArrayList is a list of *objects*. For example the add method is
boolean add(Object object)
because of "upcasting" you can add references to any object to an ArrayList, but primitive values are not objects.
3. As far as database fields go, I prefer representing a number as an Integer versus an int so that I can use Java's null to represent an unset variable or the database NULL value.
Be careful if you are getting values from a nullable field. Calling rs.getInt(field) will return 0 if the field is NULL. Then you have to call rs.wasNull() to distinguish between these two cases.