This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes growable array of primitive type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "growable array of primitive type" Watch "growable array of primitive type" New topic
Author

growable array of primitive type

Pin Ting
Greenhorn

Joined: May 28, 2003
Posts: 22
Dear all ranchers,
The Vector and ArrayList accept object only, and I found it not convenient to use. So I wonder is there any easy way to do this in Java:
GrowableArray ga = new GrowableArray();
ga.pushBack(4);
ga.pushBack(38);
int tmp = ga.popBack();
Thanks.


Never do things the hard way if you don't have a good reason.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
The J2SE Collections accept only Objects, as you've pointed out. I have noticed third party, open source, free Collections that work with primitives. You might want to try a quick search on Google. You could always write your own primitive Collection without too much work.
In the future, with Java 1.5, the compiler will autobox and unbox primitives as necessary. So, you'll be able to say myArrayList.add(13), and the compiler will step in and rewrite the code as myArrayList.add(new Integer(13)), saving us programmers some steps.
[ July 11, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Pin Ting
Greenhorn

Joined: May 28, 2003
Posts: 22
That's a good news. I'm looking forward to coding with JSDK 1.5!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: growable array of primitive type
 
Similar Threads
Text box value is not being completely filled with request attribute
WA #1.....word association
The x900 effect ?
Cant use object from another class
Posting to bump up my count...