How to initialize arrays in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to initialize arrays in java?

I remember in c++ you could initialize arrays using two for statements, one for index and the other one for the value. How is it like in Java?

13th Apr 2018, 8:36 AM
Mohammad Ghahraman
Mohammad Ghahraman - avatar
4 Answers
+ 8
13th Apr 2018, 12:05 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 8
Refer to this lesson on Array: https://www.sololearn.com/learn/Java/2148/
13th Apr 2018, 9:48 AM
Shamima Yasmin
Shamima Yasmin - avatar
0
I already saw the lesson. I want to know how to initialize array values in a specific sequence, like assigning 0 to 10 using for, while or some other statement.
13th Apr 2018, 9:53 AM
Mohammad Ghahraman
Mohammad Ghahraman - avatar
0
well you can declare an array with curly brace and put all the index values inside the curly brace. Like: int[] data = {10,20,30,40,50,60,71,80,90,91}; but the efficient way is to declare the index range and then put in the values using a loop dynamically.
18th Apr 2018, 2:34 AM
Nahid Anik
Nahid Anik - avatar