-3
  public boolean makeReservation(int id, AvilaNatalyPassenger request) {
    boolean status = true;
    ArrayList<Integer> inputValues = new ArrayList<Integer>();
        for (int i = 0; i < 22; i++) {
            for (int j = 0; j < 5; j++) {
             id = seats[i][j];
                if (id != -1) {
                    if (inputValues.contains(id)) {
                    status = false;
                    break;
                    }
                    else {
                    inputValues.add(id);
                    for(int a = 0; a < inputValues.size; a++)
                        seats[a] = inputValues[a];

                    }
                }
            }
         }

 return status;
 }

This is what I have but its not correct. I need to add what I have in inputVaule arrayList into the array seats.

code4jhon
  • 5,725
  • 9
  • 40
  • 60
  • I have no idea what this code is supposed to do. Could you please explain what you are trying to achieve, and where it goes wrong? – Keppil Dec 08 '13 at 19:05
  • Try with toArray: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#toArray%28T[]%29 – Blub Dec 08 '13 at 19:06
  • this method should directly accesses array seats to determine whether the seat is already taken. If not, record the id at that position in seats. Return true if you make the reservation and false if it is already taken. The problem I'm having is adding the positions to seats. – user3026678 Dec 08 '13 at 19:30

2 Answers2

1

You can also look at the Java API: http://docs.oracle.com/javase/7/docs/api/index.html?java/util/ArrayList.html

public Object[] toArray()

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

So this is what you could do:

seats[a] = inputValues.toArray();

Furthermore you cannot use inputValues[a] since it is not an array. What you probably could do is

seats[a] = (inputValues.toArray())[a];
dwettstein
  • 667
  • 1
  • 7
  • 17
0

To answer your question, here is an example:

ArrayList<String> stock_list = new ArrayList<String>();
stock_list.add("stock1");
stock_list.add("stock2");
String[] stockArr = new String[stock_list.size()];
stockArr = stock_list.toArray(stockArr);
for(String s : stockArr)
    System.out.println(s);

Example is taken from here

Community
  • 1
  • 1
Stefan Freitag
  • 3,578
  • 3
  • 26
  • 33