The Artima Developer Community
Sponsored Link

Java Buzz Forum
Arrays in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Arrays in java Posted: Jan 12, 2015 9:47 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Arrays in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

Array:

  • Array is referenced data type used to store multiple values of same type in continues memory locations with single variable name.
  • The size of array can not change at the run time.
  • Once the memory has been allocated for an array that memory can not be altered at the run time.
  • Java arrays are objects.

Need of array:

  • In projects array is used to collect similar type of objects to send all those values with single call.

Problem of primitive data types:

  • Using primitive data types we can not store values in continuous memory locations.
  • Due to this limitation we have two problems.

1.we cant store multiple values:

  • If we want to store multiple values , say 1 to 10 , we must create 10 variables .
  • All those 10 variables are created at different locations.

2. we can not pass multiple values in single call:

  • Using primitive variables we can not pass all values to the remote computer with single network call , which increases burden on network and also increase lines of code in program.

Solution:

  • To solve above two problems , values must be stored in continuous memory locations with single variable name. 
  • This can be possible using array.
  • In java array is reference data type . it is used to store fixed number of multiple values of same type in continuous memory locations.
  • Like other data types array is not a keyword it is a concept. it creates continuous memory locations using other primitive or reference types.

 Array Limitation: 

  •  Array size is fixed , means we can not increase or decrease its size after its creation.

Array Declaration:

  • <Accessibility modifier><Modifier><datatype>[] <array variable name>;

For example:

  • public static int[] i;
  • public static Example[] e;
  • Like in C or C++ , in java we can not mention array size in declaration part. It leads Compile time error.
  • int[5] i; Compile time Error: illegal start of expression
  • int [] i;

Possible declaration:

  1. After data type : int[] i;
  2. Before variable name : int []i;
  3. After variable name : int i[];

Type of arrays:

  1.  Single dimensional : int [] i;
  2. Two dimensional : int[][] i;
  3. Three dimensional : int [][][] i;

Array object creation:

  • <Accessibility Modifier><Modifier><data type>[]<array name>={<list of values with , separator>};
  • int [] ia={10,20,30,40};

Read: Arrays in java

Topic: java.util.regex.Pattern Example Previous Topic   Next Topic Topic: IDC Report on Business Value of using JBoss Fuse (with Apache Camel)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use