


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Arrays, Strings and Vectors Arrays Arrays are the data structures which consist of collection of data elements of same data type. Arrays have fixed length once they are declared their size cannot be changed. In JAVA arrays are Objects Arrays can be declared and initialized. e.g. Creation of an array has three steps
Array Length We can get the length of an array by using arrayname.length. e.g: int var= no.length; JAVA supports single dimentional,two dimentional ,multidimentional and variable size arrays. Program to sort an array of integer numbers import java.io.*; class sort { public static void main(String args[]) { int a[]={14,32,25,17,29}; int i,j,temp; System.out.println(" elements before sorting are: "); for(i=0;i<5;i++) System.out.print("\t"+a [i]); for(i=0;i<5;i++) for(j=0;j<4-i;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=tem p; } } System.out.println(" elements after sorting are: "); for(i=0;i<5;i++) System.out.print("\t"+a[i]); } }