Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Study Note on JAVA - Arrays, Strings & Vectors

Rating
-
Sold
-
Pages
4
Uploaded on
28-02-2022
Written in
2021/2022

Study Note on JAVA - Arrays, Strings & Vectors

Institution
Course

Content preview

Chapter 9: Arrays, Strings and Vectors
9.1 Arrays
 An array is a group of contiguous or related data items that share a common name.
 A particular value is indicated by writing a number called index number or subscript in
brackets after the array name.
Eg: salary[10]
 The complete set of values is referred to as an array, the individual values are called
elements.
 Arrays can be of any variable type.
 The ability to use a single name to represent a collection of items and to refer to an item
by specifying the item number enables to develop concise and efficient programs.
9.2 One-Dimensional Arrays
 A list of items can be given one variable name using only one subscript and such a
variable is called a single-subscripted variable or a one-dimensional array.
9.3 Creating an Array
 Creation of an array involves three steps:
1. Declare the array
o Arrays can be declared in 2 forms:
1. type arrayname[];
2. type[] arrayname;
Eg:
int number[];
int[] counter;
2. Create memory locations
o Allows us to create arrays using new operator
Arrayname = new type[size];
Eg:
Number = new int[5];
These lines create necessary memory locations for the arrays number and designate as int.

3. Put values into the memory locations
o The final step is to put values into the array created. This process is called
initialization.
o This can be achieved using the array subscripts:
Arrayname[subscript] = value;
Eg: array[0] = 45
o We can also initialize arrays automatically in the same way as the ordinary
variables when they are declared.
type arrayname[] = {list of values};
Eg: int number[] = {23,34,45,67};
 Array length
o All arrays store the allocated size in a variable named length.
o We can access the length of the array ‘a’ using a.length
Eg: int aSize = a.length
9.4 Two-Dimensional Arrays
 For creating 2-dimensional arrays:
int myArray[][];
myArray = new int[3][4];

Connected book

Written for

Institution
Course

Document information

Uploaded on
February 28, 2022
Number of pages
4
Written in
2021/2022
Type
Class notes
Professor(s)
Mrs. prabitha
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sinithomas

Also available in package deal

Get to know the seller

Seller avatar
sinithomas Study Notes
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions