I want to create an int array with 999 elements, each of which has value 999. Is there a way to initialize an int array during declaration instead of iterating through each element and setting its value to 999?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the array was small, e.g. only 3 items, you could do as follows::
But if it grows and you don’t want to repeat yourself, then better use
Arrays#fill(). It hides theforloop away for you.