Arrays:- When there is a need to use many variables then we There is a big problem because we will Conflict with name of variables So that in this Situation where we wants to Operate on many numbers then we can use array .
Arrays are Set of Elements having Same data type or We can Say that Arrays are Collection of Elements having same name and same data type But Always Remember Arrays are Always
Start From its index value and the index of array is start From 0 to n-1. Suppose we wants to Access 5th Element of array then we will use 4th Element Because Arrays are Start From 0 and arrays are always stored in Continuous Memory Locations The Number of Elements and Types of array are Identified by Subscript of array Elements. The Various types of Array those are provided by java as Follows:-
1) Single Dimensional Array:- These are Mostly used when we wants to declare number of Elements Single Dimensional arrays are used for Using Many elements and they are Declared with Single Bracket Like int a [] etc. the Bracket will specify the size of array Elements Means how many array elements are declared and used For Accessing or using a variable we have to Specify the Index Value in the Sub Script or in Bracket of Array Variable.
The [] is used for dimensional or the sub-script of the array that is generally used for declaring the elements of the array For Accessing the Element from the array we can use the Subscript of the Array like this
a[3]=100
So there is only the single bracket then it is called as Single Dimensional Array
The Syntax For Declaring Array Elements in java is as FollowsL-
Int a[]=new int[5]
Note the new Keyword this is a Special Operator Which is usef for Creating new Memory which is Continuous in nature and The new Keyword is Also Creating For Memory For Number of elements That is Specified in Single bracket.
2) Two Dimensional Array :- The Two Dimensional array Elements are used when we Wants to Perform the Operation in Matrix Forms the Two Dimensional arrays are used For Creating Matrix and Displaying array elements in the Form of Rows and Columns The Total Elements of Arrays Will be Calculated by Multiplying the Elements of Rows and Columns Like int a[3][3] i. e 9 Elements will be used by Array These are Called as Two Dimensional Because they use two Brackets.
Like this int a[3][3]
So This is the Example of the Two Dimensional Array In this first 3 represents the total number of Rows and the Second Elements Represents the Total number of Columns The Total Number of elements are judge by Multiplying the Numbers of Rows * Number of Columns in The Array in the above array the Total Number of elements are 9
The Two Dimensional arrays are Declared as Follows:-
Int a[][]=new int[3][3] .
String :- Like an integer characters are also be in the Array The Array of Characters are called as the Strings They are Generally used for representing the Strings in java String is Also Array and Also a Class .we Know that when Collection of Characters are called as String In java For Creating an String array You Will use as Follows:-
String s[]=new String[10];
Here is the s is an array of type String Means it can accept only 10 Characters but if you will use String as then:-
String s==new String(“Welcome To Strings”)
S is an object of Class String and now you can use any Method From String Class The Various String Methods those are Reside in String Class are :-
Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Search Content
Popular Article
Basic Courses
Advance Courses