Results 1 to 6 of 6
- 03-26-2012, 10:31 PM #1
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
- 03-26-2012, 10:34 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: How to declare an ArrayList that can hold int variables
ArrayList<Integer>
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 03-26-2012, 10:38 PM #3
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Re: How to declare an ArrayList that can hold int variables
Hi Jos,
Thanks.
But I want to use something like:-
Java Code:int rand = (int) (Math.random()* 5); ArrayList<Integer> loc = {rand, rand+1, rand+2};
- 03-26-2012, 10:42 PM #4
Re: How to declare an ArrayList that can hold int variables
An ArrayList is different from an Array.
You need to initialize your ArrayList first, then add your elements to the ArrayList.
Java Code:ArrayList<Integer> loc = new ArrayList<Integer>(); loc.add(rand); loc.add(rand+1); loc.add(rand+2);
Last edited by sehudson; 03-26-2012 at 10:45 PM.
- 03-26-2012, 11:01 PM #5
Member
- Join Date
- Dec 2011
- Location
- India
- Posts
- 74
- Rep Power
- 0
Re: How to declare an ArrayList that can hold int variables
thanks i got your point.
- 08-20-2014, 11:37 AM #6
Member
- Join Date
- Aug 2014
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
ArrayList contains two children of a class - how do I set variables of extensions ?
By Jadeclan in forum New To JavaReplies: 10Last Post: 03-05-2012, 06:44 AM -
Texas Hold'em Poker
By JohnPringle83 in forum Java GamingReplies: 0Last Post: 05-05-2011, 06:40 AM -
A private static ArrayList hold an object and static getter ArrayList
By Louis in forum New To JavaReplies: 2Last Post: 11-16-2010, 06:51 PM -
Creating a Data Structure to Hold an Array and Distance Value
By rdoane in forum New To JavaReplies: 11Last Post: 04-01-2009, 04:43 AM -
How to declare and initalize application space variables
By thagentleman in forum New To JavaReplies: 2Last Post: 10-11-2008, 08:19 PM
Bookmarks