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>();
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.
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.
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.
num[count]
is wrong, since num
is not an array. Use num.get(count)
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With