开发者

How to cast an ArrayList of objects to float in Processing

开发者 https://www.devze.com 2023-02-28 20:47 出处:网络
ArrayList a = new ArrayList(); for(int i = 0; i < a.size(), i++) { fl开发者_C百科oat f = float(a.get(i));// ERROR : cant convert Object to float
ArrayList a = new ArrayList();

for(int i = 0; i < a.size(), i++)

{

    fl开发者_C百科oat f = float(a.get(i));  // ERROR : cant convert Object to float

}


Processing is a simpler java, so you can use the java syntax:

ArrayList<Float> a = new ArrayList<Float>();

a.add(1.0f); // "Autobox" a float into a Float object, adding it to the array

for (int i = 0; i < a.size(); i++)
{
    float f = a.get(i); // "Unbox" the Float object
}

Lookup autoboxing/unboxing.


Must not be .NET, otherwise would be i < a.count;

float f = (float)(a.get(i)); ??

0

精彩评论

暂无评论...
验证码 换一张
取 消