Results 1 to 4 of 4
- 01-26-2011, 02:59 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Converting Program from ArrayLists to Arrays
I built a program using ArrayLists, and now need to convert them Arrays. I've managed to convert some of the parts, but how can I convert lines like:
Java Code:import java.util.Random; public class CarLot { private static int [] tile; public CarLot() { car = new int[3]; for (int i = 0; i < 4; i++) { Random generator = new Random(); int random = generator.nextInt(9) + 1; car[i] = random; } } public Car(int [] startingCar) { tile = (startingCar; } }// end NumberTile
Java Code:import java.util.Arrays; public class CarGame { private Arrays [] board; public CarGame() { board = new Arrays[0]; } public Arrays[] getPart() { Arrays [] part = new part[5]; for (int i = 0; i < 6; i++) { [COLOR="Red"]part[i] = (new CarLot());[/COLOR] } return part; } public int getIndex(CarLot car) { [COLOR="Red"]CarLot = board[0]; CarLot Right = board[board.size() - 1];[/COLOR] ... }
Cheers.
- 01-26-2011, 03:03 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
I do not see any ArrayList. This compile? If no kindly post the complete error message
- 01-26-2011, 03:29 AM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Bangalore, India
- Posts
- 102
- Rep Power
- 0
I haven't tried it but this will do i suppose
ArrayList (Java 2 Platform SE v1.4.2))
So you just have to do
Object[] arr1 = arrayListObject.toArray();
Not sure whether you can convert Object[] to int[]
Somebody else, please help. Even I had this doubt and was about to post.
- 01-26-2011, 09:02 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Arrays or ArrayLists
By mwenchong in forum New To JavaReplies: 3Last Post: 12-17-2010, 01:23 AM -
Converting an array program to ArrayList
By Adomini in forum New To JavaReplies: 4Last Post: 10-13-2010, 07:22 PM -
program with converting feet to meters
By Smitty300 in forum New To JavaReplies: 5Last Post: 03-16-2010, 11:41 AM -
Converting arrays
By locke19 in forum New To JavaReplies: 2Last Post: 02-24-2010, 07:40 AM -
A Number Converting Program!
By WastedxYears in forum New To JavaReplies: 2Last Post: 01-09-2010, 12:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks