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 Usage

                         

We have already discussed that to refer an element within an array, we use the [] operator. The [] operator takes an "int" operand and returns the element at that index. We also know that the array indices start with zero, so the first element will be held by the 0 index. For Example :-
i
nt month = months[4];    //get the 5th month (May)

Most of the times it is not known in the program that which elements are of interest in an array. To find the elements of interest in the program, it is required that the program must run a loop through the array. For this purpose "for" loop is used to examine each element in an array. For example :-

String months[] = 
         {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 
          "July", "Aug", "Sep", "Oct", "Nov", "Dec"};
           //use the length attribute to get the number
          //of elements in an array
          for (int i = 0; i < months.length; i++ ) {
          System.out.println("month: " + month[i]);

Here, we have taken an array of months which is,

     String months[] =
                           {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                            "July", "Aug", "Sep", "Oct", "Nov", "Dec"};

Now, we run a for loop to print each element individually starting from the month "Jan".

    for (int i = 0; i < months.length; i++ )

In this loop int i = 0; indicates that the loop starts from the 0th position of an array and goes upto the last position which is length-1, i < months.length; indicates the length of the array and i++ is used for the increment in the value of i which is i = i+1.

 

                         

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 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

I want to make project in Java
but I don't Know how to Combine all programs so that project should be completed???????????????

Posted by SANDEEP on Wednesday, 08.6.08 @ 10:01am | #71254

i need to declare an array of an object customer like:
customer[] cust = new customer[10];
a customer record has firstname,surname,phone number that i need to store into the array.
iam allow to store ten customer in the array.the thing is each customer contains these details firstname,surname....
how can i do that ????

Posted by olivier on Thursday, 06.12.08 @ 19:32pm | #63126

Latest Searches:
pdf box ge text
jQuery to text changes
ant script to telnet
Rename the File or Dir
DAO class
java deployment
2 resultset
how to pass same varia
relative path in web a
annotation
create xls using POI
How to Validate a File
sample application on
servlet jsp project
basic about struts
JSP:select Input type
Tomahawk jscookMenu ta
activate email account
read keys of propertie
session form session i
Java Tutorials
create xml using java
Create XML file from f
Color
file upload in structs
java random numbers
how to create tree str
add picture to a swing
insert image in databa
string to date
connect SQL server in
selecting option value
How to get data from d
ntt beans
factorial
EXAMPLE PROGRAME USING
Flash Dynamic Content
MULTIPLE SELECT COMBO
download tomcat
jsp Insert data in mys
application of java we
String to array in jav
j2me programing code
comparable
dynamic metatags
Drawing Dragon Wings
single level inheritan
ejb2.0
adding label and textb
convert decimal binary
https
Photoshop Drawing Drag
Fill an input field wi
drill down using jfree
Hash Function in Java
update all columns of
file upload examplein
gui
DriverManager.getConne
struts 1 date picker e
transact sql
Photoshop Photo Retouc
program to draw circle
diplay North American
how to create war file
setBounds
Excel open java applic
jsp:plugin attribute
how to change url
dynamic array value
Javascript Mouse Trick
struts2 action element
jsp bean
struts 2 ajax
return type-methods
actionperformed
a simple calculator pr
visual C 6.0
html sample
insert image in databa
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.