Im confusing about concept of an array in javaEclipse Give m
I\'m confusing about concept of an array in java(Eclipse). Give me some examples of using the array in java as a code, please.
Solution
Answer :
Array :
1) Array is a collection of similar type of elements that have contiguous memory location.
2) Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array.
3) Array in java is index based, first element of the array is stored at 0 index.
Example :
public class JavaStringArrayTest
{
private String[] arraystringleanth = {\"Cheese\", \"Pepperoni\", \"Black Olives\"};
// our constructor; print out the String array here
public JavaStringArrayTest()
{
// old `for` loop
int size = arraystringleanth.length;
for (int i=0; i<size; i++)
{
System.out.println(arraystringleanth[i]);
}
}
// create a new instance of our class here.
public static void main(String args[])
{
new JavaStringArrayTest();
}
}
