Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Java Array Initialization

                         

After declaring an array variable, memory is allocated to it. The "new" operator is used for the allocation of  memory to the array object. The correct way to use the "new" operator is

       String names[];   

         names = new String[10];

Here, the new operator is followed by the type of variable and the number of elements to be allocated. In this example [] operator has been used to place the number of elements to be allocated.

Lets see a simple example of an array,

public class Sum 
{
  public static void main(String[] args) 
  {
    int[] x = new int [101];
    for (int i = 0; i<x.length; i++ )
      x[i] = i;
    int sum = 0;
    for(int i = 0; i<x.length; i++)
      sum += x[i];
      System.out.println(sum);
  }
}

In this example, a variable 'x' is declared which  has a type array of int, that is, int[]. The variable x is initialized to reference a newly created array object. The expression 'int[] = new int[50]' specifies that the array should have 50 components. To know the length of the Array, we use field length, as shown.

Output for the given program:

C:\tamana>javac Sum.java

C:\tamana>java Sum
5050

C:\tamana>

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
substring
jsp to microsoft sql
excel style sheet
demo project on swings
ะà?2à¸?ะà? à¸?ะà
Java returns Vowels in
bean
how to retrieve image
struts2 annotation
transact
file to string
sum of numbers by grou
To avoid potential dea
3DS MAX Modeling the m
relative path
EJB example program
jsp and javabeans
jsf with jboss
cololection examples
how to create a textbo
<interceptor-ref name
Date
ajax auto complete
source code to send te
ascii
how to insert large im
ASP.NET .NET Add text
deployment java progra
Button
java trim
jstl list size
<sql-query>
MULTIPLE SELECT COMBO
how to read txt file f
convert string to stin
iReport
struts2 ajax
multiple ajax combo
paging and sorting wit
b tree implementation
url
covertir texte to bina
pagination
free download of java1
Photoshop Digital Art
websphere portals
sample projects on jsp
oracle.jdbc.driver.Dat
use dropdownlist in js
list iteration in java
Java Bitwise XOR
login eample code usin
selection model
heap sorting
optgroup
swing close button
Class
Error handling in stru
callablestatement
action
soket programming
request_locale
relative
Statless session bean
getter setter methods
Java Count Vowels
Downloading and Instal
adding label and textb
fireTableCellUpdated
Photoshop Abstracts Ab
diff b/w function and
default path
ASP Form Processing Se
telephone
Swing component for en
tree component web jav
binary recursion
Creating a DSN for MyS
source code of game i
Action list
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.