I want to create an ArrayList<Float> of length 350. I did this:
x = new ArrayList<Float>(350);
No i want this array to have 'zero' float value at each point. i can do this:
for (int i = 0; i< 350 ; i++){
x.add((float) 0.0);
}
So my question is if there is another way to do the same thing without iterating. I want minimum iterating to increase efficiency.
O(n)is pretty efficient. You should worry about making other, less efficient areas, more efficient. You cannot initialize an arraylist with default values. The constructor only allows for a cap, nothing, or a collection of values.0.0f. That way you don't need to cast it to float. But note that using double instead of float is a good decision in most cases, because almost all Java math functions take and return doubles. When you also use doubles, you avoid unnecessary casting.