answersLogoWhite

0


Best Answer

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the language

Arrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.

To create an array in java ,use three steps

1. Declare a variable to hold the array

2. Create a new array object and assign it to the array variable

3. Store things in that array

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

int size=10;

int a[]=new Int[size];

this is static initialization;

int aa[]=null;

int size;

size you can take from your applicatin

aa[]=new int[size];

this is what dynamic initialization

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you initialize an array variable in java program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How does one initialize a byte array in Java?

One can get information about how to initialize a byte array in java on the website stackoverflow dot com. That website can learn one a lot about java.


How do you initialize variable?

initialize simple types: int i = 0; initialize objects: Object o = null; (in java)


Variable lnitialization in java language?

I suppose you want to ask about variable initialization.Java initialize its variables in its constructor.


Can you initialize an object without constructor in java?

No. if you wish to create an object that you plan on using in a java program then the answer is NO. You cannot initialize an object of a Java class without calling the constructor.


Write a java program to initialize array of string with the days of the week?

final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};


What is an error in java?

An error or more commonly known as an Exception is a situation where the java program behaves in a way it is not supposed to do so. It is a problem in the code that is causing the JVM to terminate or throw error messages in the console. Ex: When you initialize an array list with 10 elements and try to access the 11th element in the array list you will get an array index out of bounds exception.


Can a java program has two different variable?

Yes. You can have as many variables as you want in Java


What is the Java program for sorting an array?

Java has a very efficient built in implementation of quick sort. You can use it on any array of primitives or Comparable Objects by invoking Arrays.sort(<array>) See related link.


What are benefits of array in java?

array example in java


Can you run java program without applying main method?

yes we can run java program without using main. we can run program by declaring the variable static..


Why might one need a sting array object in Java?

One might need a sting array object in Java to use protective measures on one's computer to prevent one's program from writing outside the bounds of the array.


What happens if you don't initialize an instance variable of any of the primitive type in java?

Java by default initializes it to the default value for that primitive type. Thus an int will be initialized to 0(zero), a Boolean will be initialized to false.