Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayList compiler error

I am trying to make an array list in Java in two spots, but I don't know what I am doing wrong. It says an array is required, but I don't know what that means because I am using an array list.

This is the line that's being messed up:

static char rSpaces(String problem, int count)
{
    num.add(problem.charAt(count));
    char no = num[count];
    return no;
}

If this helps, this is the line I created the array list in (I already imported it):

static ArrayList<Character> num = new ArrayList<Character>();
like image 463
user2371168 Avatar asked May 10 '13 18:05

user2371168


People also ask

Can you use .equals for ArrayList?

You can compare two array lists using the equals() method of the ArrayList class, this method accepts a list object as a parameter, compares it with the current object, in case of the match it returns true and if not it returns false.

How do you reset an ArrayList in Java?

We can use ArrayList. clear() or ArrayList. removeAll() method to empty an ArrayList. The clear() method is the fastest as it only set the reference to the underlying array as null while the removeAll() will perform some additional work.

How do you resize an ArrayList in Java?

However, ensureCapacity() method of java. util. ArrayList class can be used to increase the capacity of an ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. Parameters: This method takes the desired minimum capacity as a parameter.


1 Answers

num[count] is wrong, since num is not an array. Use num.get(count) instead.

like image 91
zw324 Avatar answered Sep 24 '22 21:09

zw324