Results 1 to 4 of 4
  1. #1
    Java-Guy is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Question 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.

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I do not see any ArrayList. This compile? If no kindly post the complete error message

  3. #3
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Unhappy

    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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,854
    Rep Power
    19

    Default

    Arrays [] part = new part[5];

    Are you sure you want an array of the class Arrays?
    Especially since Arrays is a helper class and has no constructor...

Similar Threads

  1. Arrays or ArrayLists
    By mwenchong in forum New To Java
    Replies: 3
    Last Post: 12-17-2010, 01:23 AM
  2. Converting an array program to ArrayList
    By Adomini in forum New To Java
    Replies: 4
    Last Post: 10-13-2010, 07:22 PM
  3. program with converting feet to meters
    By Smitty300 in forum New To Java
    Replies: 5
    Last Post: 03-16-2010, 11:41 AM
  4. Converting arrays
    By locke19 in forum New To Java
    Replies: 2
    Last Post: 02-24-2010, 07:40 AM
  5. A Number Converting Program!
    By WastedxYears in forum New To Java
    Replies: 2
    Last Post: 01-09-2010, 12:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •