0

I can never find what that code perform:

functionName(new float[]{factor});

is it array declaration? I mean:

new float[]{factor}

it is equal to

float[] arrayName = new float[factor];

?

4 Answers4

2
new float[]{factor} 

is just one type of array declarations in Java. It creates a new float array with factor value in it.


Another ways how we can declare arrays:

For primitive types:

int[] myIntArray = new int[3];
int[] myIntArray = {1,2,3};
int[] myIntArray = new int[]{1,2,3};

For classes, for example String, it's the same:

String[] myStringArray = new String[3];
String[] myStringArray = {"a","b","c"};
String[] myStringArray = new String[]{"a","b","c"};

Source from How do I declare and initialize an array in Java?

Community
  • 1
  • 1
Matej Špilár
  • 2,513
  • 3
  • 13
  • 27
1
new float[]{factor}

This piece of code creates a float array with a single element and that element is factor.


functionName(new float[]{factor});

And this means that you're calling the method functionName() and passing a single-element float array to it, where that single element is factor.

RainMaker
  • 41,717
  • 11
  • 78
  • 97
0

It means you are passing an anonymous array to the function as an argument and No, it doesn't mean that factor is the length of array.
It means:

float factor = 0.5f;
float[] array = {factor};
function(array);
Abdul Fatir
  • 5,494
  • 5
  • 24
  • 54
0
functionName(new float[]{factor});

Calls a function named: functionName passing a new array (anonymous) with one element as an argument, which is the contents of factor.

d'alar'cop
  • 2,342
  • 1
  • 12
  • 17