Float in Array

Hi guys,

I want to ask u how to define float with array. The case is I need to get attribute value from the web and stored it to the array in float, but I have a problem even how to declare the float in array.

Can u give me some hint? Thanks before :slight_smile:

Hi there,

basically, you define Float array like this:

Float[] floatArray = [1.22, 2.33, 3.44, 4.55]

But there is a problem with arrays - you can not add more values after you create it.
Instead, Iā€™d prefer to create ArrayList and as soon as you get all values from UI, convert it to array.

List<Float> floatValues = new ArrayList<>()floatValues.add(1.22)floatValues.add(2.33)floatValues.add(3.44)floatValues.add(4.55)Float[] floatArray = floatValues.toArray()println floatValues.get(2)println floatArray[2]//console3.443.44

However, getAttribute() method returns String, so you have convert it to Float type before you add it into a list:

String s = WebUI.getAttribute(testobject, "id")Float yourFloatValue = Float.parseFloat(s)

2 Likes

Whoaa, thanks for the answer, example, and of course to your explanation of using list than array, Marek. It works really well.

Thank you so much :slight_smile: