-1

I am new to Java and I have an array

int [] A = {140,150,160,170,180,190}

I need to add infinity at the beginning of the array

like so:

int [] A = {inf,140,150,160,170,180,190}

I know from Python to do it like so:

A=[140,150,160,170,180,190]
A=[float('inf')]+A

I need a way to do that in Java as simple as Python without loops

It's important to say I need the array / list(A=[140,150,160,170,180,190]) to be given with the code.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Itay Drori
  • 13
  • 3

1 Answers1

0

You can use Java ArrayList that implements List interface and has a method add(int,E) So, you can use something like list.add(0, myObj);.

aviad
  • 8,229
  • 9
  • 50
  • 98