-2

I have a simple question. How can i create by using ArrayList that data structure in Java ?

 vector< complex<float> > *v1;
 v1 = new vector< complex<float> >;

I tried something like this:

ArrayList< Complex<float> > v1;

but dont work :/

(I included 'Apache commons math' jar for complex numbers)

Grigo
  • 1
  • 1
  • I understand your question though! It's a normal doubt when you start with java. The reason lies in `type erasure`. Any generic type at runtime is converted to `java.lang.Object` and cast at needed times. This can't happen with a primitive type. You'll find plenty of info on that! – payloc91 May 30 '18 at 19:38

1 Answers1

0

Java does not support primitive generics right now (Possibly in Java 11). You will need to use the wrapper class, which will come with a performance hit.

List<Complex<Float>> list;

You may want to create your own complex number class.

killjoy
  • 3,665
  • 1
  • 19
  • 16
  • Why reinvent the wheel? Also, I can't believe that the performance hit is **so** large in boxing and unboxing for almost all operations. – ifly6 May 30 '18 at 18:46
  • https://stackoverflow.com/questions/1570416/when-to-use-wrapper-class-and-primitive-type – killjoy May 30 '18 at 18:48