1

I am working on a calculator like assignment for my data structures class, and I have to input symbols into the array list defined as

ArrayList<ScalarSymbol> scalar;

and I have been trying to input values into it by doing this:

scalars.add(0,')');

and it tells me that the char type is not the correct syntax for the <ScalarSymbol> array. I don't know how to find out what types the array will take, is there bind I have to use in order to make it accept chars?

Klitos Kyriacou
  • 10,634
  • 2
  • 38
  • 70
JAY PATEL
  • 25
  • 2
  • I'm curious, what lead you to believe that `add(0, ')')` would do what you want? The [`ArrayList.add()` documentation](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#add-E-) should be your canonical reference (and you can see it only takes one parameter), along with the [collections tutorial](https://docs.oracle.com/javase/tutorial/collections/) which covers interacting with `ArrayList` and other generic collections. – dimo414 Feb 23 '17 at 20:09

1 Answers1

1

Just create an instance of the object you want to add:

ScalarSymbol s = new ScalarSymbol();

Then add it to the list:

scalar.add(s);

The array list only takes the type written in these:

<type>
mrhallak
  • 1,138
  • 1
  • 12
  • 27