Difference between revisions of "Java/C2/Array-Operations/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with ''''Title of script''': for loop in Java '''Author''': TalentSprint '''Keywords:''' conditions, loops, for loop, video tutorial {| style="border-spacing:0;" | style="border:1…')
 
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Title of script''': for loop in Java
+
'''Title of script''': Array Operations
  
 
'''Author''': TalentSprint
 
'''Author''': TalentSprint
  
'''Keywords:''' conditions, loops, for loop, video tutorial
+
'''Keywords:''' array operations, java, sort, fill, copy, video tutorial
  
  
Line 15: Line 15:
  
 
'''Welcome'''
 
'''Welcome'''
| style="border:1pt solid #000000;padding:0.097cm;"| Welcome to the spoken tutorial on '''for loop'''.
+
| style="border:1pt solid #000000;padding:0.097cm;"| Welcome to the spoken tutorial on '''Array Operations '''in java.
  
 
|-
 
|-
Line 21: Line 21:
  
 
'''Learning Outcomes'''
 
'''Learning Outcomes'''
| style="border:1pt solid #000000;padding:0.097cm;"| In this tutorial, you will learn how to use the '''for loop in Java.'''
+
| style="border:1pt solid #000000;padding:0.097cm;"| In this tutorial, you will learn how to  
 +
 
 +
'''import the class Arrays '''and,
 +
 
 +
'''perform basic operations on arrays'''.
  
 
|-
 
|-
Line 29: Line 33:
 
| style="border:1pt solid #000000;padding:0.097cm;"| For this tutorial we are using  
 
| style="border:1pt solid #000000;padding:0.097cm;"| For this tutorial we are using  
  
* '''Ubuntu 11.10''',  
+
'''Ubuntu 11.10''',  
* '''JDK 1.6''' and
+
* '''Eclipse 3.7.0'''
+
  
 +
'''JDK 1.6''' and
  
 +
'''Eclipse 3.7.0'''
  
 
|-
 
|-
Line 39: Line 43:
  
 
'''Prerequisites'''
 
'''Prerequisites'''
| style="border:1pt solid #000000;padding:0.097cm;"| For this tutorial, you should have knowledge on '''relational operators in Java.'''
+
| style="border:1pt solid #000000;padding:0.097cm;"| For this tutorial, you should have knowledge on''' arrays in Java.'''
  
  
If not, please go through the tutorials on these topics available at our website [http://spoken-tuitorial.org/ http][http://spoken-tuitorial.org/ ://][http://spoken-tuitorial.org/ spoken][http://spoken-tuitorial.org/ -][http://spoken-tuitorial.org/ tutorial][http://spoken-tuitorial.org/ .][http://spoken-tuitorial.org/ org][http://spoken-tuitorial.org/ .]
+
If not, for relevant tutorial please visit our website which is as shown [http://spoken-tutorial.org/ http][http://spoken-tutorial.org/ ://][http://spoken-tutorial.org/ spoken][http://spoken-tutorial.org/ -][http://spoken-tutorial.org/ tutorial][http://spoken-tutorial.org/ .][http://spoken-tutorial.org/ org]
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 5
 
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 5
  
'''Syntax'''
+
'''import java.util.Arrays;'''
| style="border:1pt solid #000000;padding:0.097cm;"| Here is the syntax of the '''for loop'''.
+
| style="border:1pt solid #000000;padding:0.097cm;"| The methods for array operations are available in a '''class '''called '''Arrays'''.
 +
 
 +
 
 +
To access them, we need to import that '''class'''.
 +
 
 +
 
 +
It is done by the statement '''import java.util.Arrays;'''
 +
 
 +
 
 +
We can access a '''method '''from the '''class'''.
 +
 
 +
 
 +
We do it by adding a '''dot''' and the method name.
  
  
Now, let us try out an example in '''Eclipse.'''
+
So '''Arrays '''''dot '''''toString''' means '''toString''' method from the  '''Arrays''' class.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Minimize Slides and open Eclipse
+
| style="border:1pt solid #000000;padding:0.097cm;"| '''Point to the code'''
  
Eclipse should contain the following code
 
  
'''public class ForLoopDemo{'''
+
Minimize Slides and open Eclipse
 +
 
 +
{Eclipse should contain the following code}
 +
 
 +
'''public class ArraysDemo{'''
  
 
'''public static void main(String<nowiki>[] </nowiki>args){'''
 
'''public static void main(String<nowiki>[] </nowiki>args){'''
Line 65: Line 84:
  
 
'''}'''
 
'''}'''
| style="border:1pt solid #000000;padding:0.097cm;"| We have the skeleton required.
+
| style="border:1pt solid #000000;padding:0.097cm;"|Now Switch to eclipse.
  
  
We have a '''class''' named '''ForLoopDemo'''.
+
We have already created a '''class''' '''ArraysDemo'''.
  
  
Let us add the '''for loop''' inside the '''main method'''.
+
Let us now import the '''class Arrays'''.
 +
 
 +
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Before the line '''public class...''', type
 +
 
 +
'''import java.util.Arrays<nowiki>;</nowiki>'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| The '''import''' statement is written before the '''class '''definition.
 +
 
 +
 
 +
So  Before '''public class''', type
 +
 
 +
 
 +
import '''java.util.Arrays'''
 +
 
 +
 
 +
This statement says that '''java''' contains a '''package '''called '''util''' which contains the class '''Arrays''' and it has to be imported.
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.097cm;"| Inside the main function, type
 
| style="border:1pt solid #000000;padding:0.097cm;"| Inside the main function, type
  
'''int i<nowiki>;</nowiki>'''
+
'''int marks<nowiki>[] = {2, 7, 5, 4, 8};</nowiki>'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Now let us add an '''array.'''
  
'''for (i = 0; i<nowiki> < 10; </nowiki>i = i + 1)'''
 
  
 +
Inside the '''main '''function,type
  
Highlight''' '''when you explain.
 
| style="border:1pt solid #000000;padding:0.097cm;"| Inside the main function, type '''int i '''''semicolon''.
 
  
 +
'''int marks '''''open close square brackets''''' '''''equal to within brackets '''''2, 7, 5, 4, 8 '''''
  
Then type '''for '''''within brackets'' '''i '''''equal to''''' 0 '''''semicolon'' '''i '''''less than '''''10''' ''semicolon''''' i '''''equal to'' '''i '''''plus '''''1'''.
+
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| In next line, type
  
 +
'''String mStr = Arrays.toString(marks);'''
  
This statement decides how the loop is going to progress.
+
 
 +
'''System.out.println(mStr);'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Now we shall use a method available in the '''Arrays''' '''class''' to get a string representation of the array and print it.
 +
 
 +
 
 +
SoType '''String mStr '''''equal to''''' Arrays '''''dot '''''toString ''''' Paranthesis  inside Paranthesis ''''' will give the array name i.emarks '''''semicolon.''
 +
 
 +
Now this '''toString''' method gives a string representation of the array.
 +
 
 +
 
 +
Now, we shall print the marks.
 +
 
 +
 
 +
So, type '''System '''''dot '''''out '''''dot '''''println ''''inside Paranthesis''''' mStr '''''semicolon.''
 +
 
 +
 
 +
Now let us look at the output so save and run the program
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Highlight i = 0
+
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output
| style="border:1pt solid #000000;padding:0.097cm;"| This is the starting condition for the loop.
+
| style="border:1pt solid #000000;padding:0.097cm;"| As we can see int the output, the '''toString''' method has given a string representation of the '''array.'''
  
  
This condition allows the variable to be initialized.
+
Now let us look at sorting the elements of the '''array'''.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight i<nowiki> < 10</nowiki>
+
| style="border:1pt solid #000000;padding:0.097cm;"| Before the line '''Arrays.toString''', type
| style="border:1pt solid #000000;padding:0.176cm;"| This is the loop running condition.
+
  
 +
'''Arrays.sort(marks);'''
  
If the condition is true then the for block will be executed.
 
  
 +
'''Highlight sort.'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| So before the line '''Arrays '''''dot '''''toString '''''within brackets '''''marks '''type '''Arrays '''''dot '''''sort(marks);'''
  
Else it will be ignored.
 
  
 +
The '''sort '''method in the '''Arrays class''', sorts the elements of the array passed to it.
  
That means when i becomes more than or equal to 10, the block is not executed.
+
 
 +
Now we are sorting the element of the array '''marks''' and then printing the string form of it.
 +
 
 +
 
 +
Let us look at the output.So save and run
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight i = i + 1
+
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output
| style="border:1pt solid #000000;padding:0.176cm;"| This states how the loop variable is going to change.
+
| style="border:1pt solid #000000;padding:0.097cm;"| As we can see in the output '''sort''' method has sorted to the array in the ascending order
  
  
Here, the value of i starts with 1.
+
Note that the '''sort''' method has changed the array itself.
  
  
It keeps increasing by 1 for every iteration of the loop until it becomes 10.
+
This type of sorting is called''' inplace sorting'''.  
  
  
Now let us do something with i.
+
It means the array which contains the elements is changed as a result of sorting.
 +
 
 +
 
 +
The next method we are going to look at, is '''fill'''
 +
 
 +
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Remove the line '''Arrays.sort''' and type
 +
 
 +
'''Arrays.fill(marks, 6);'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| The fill method takes two arguments.
 +
 
 +
 +
 
 +
Remove the sorting line and
 +
 
 +
 
 +
Type '''Arrays '''''dot '''''fill '''''within brackets''''' the name of the arrays i.e marks;'''
 +
 
 +
This is our first argument and second is the value that should be felt in the array we will give it 6 and semicolon. Save and Run
 +
 +
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output
 +
| style="border:1pt solid #000000;padding:0.097cm;"| As we can see, as the name goes, the fill method fills the array with the given argument i.e 6
 +
 
 +
 
 +
The next method we are going to look at, is '''copyOf'''
 +
 
 +
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Remove the '''Arrays.fill..''' line and type
 +
 
 +
'''int marksCopy<nowiki>[];</nowiki>'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| We are going to copy all the elements of the array '''marks''' into the array '''marksCopy'''
 +
 
 +
So remove arrays dot fill
 +
And Type '''int marksCopy<nowiki>[];</nowiki>'''
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Change for (i = 0; i<nowiki> < 10; </nowiki>i = i + 1) to for (i = 0; i<nowiki> < 10; </nowiki>i = i + 1) {
+
| style="border:1pt solid #000000;padding:0.097cm;"| In the next line, type
  
System.out.println( i * i );
 
  
}
+
'''marksCopy = copyOf(marks, 5);'''
  
  
Highlight the println statement and explain.
+
Change '''toString(marks)''' to '''toString(marksCopy)'''
| style="border:1pt solid #000000;padding:0.097cm;"| Now, open curly brackets.
+
| style="border:1pt solid #000000;padding:0.097cm;"|next line,
 +
Type '''marksCopy = copyOf(marks, 5);'''
  
  
Next line type '''System''' ''dot''''' out '''''dot '''''println''' within brackets '''i''' ''into'' '''i'''.
+
This method takes two arguments.  
  
  
This will print the square of each number from 1 to 10.
+
The first argument is the name of the  array from which you want to copy the elements.i.e marks
  
 +
  the second is the no.of elements to copy overhere we will copy 5.
 +
Then in arrays dot strings changes marks to marks copy
  
Let us see the output.
 
  
  
So '''save''' and '''run''' the file.
 
  
 
|-
 
|-
 
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output
 
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output
| style="border:1pt solid #000000;padding:0.097cm;"| As we can see, the loop ran over numbers from 1 to 10.
+
| style="border:1pt solid #000000;padding:0.097cm;"| Now save and run the program
  
 +
We see that the elements of the array '''marks''' have been copied to the array '''marksCopy'''.
  
The square of the number has been printed in each iteration.
 
  
  
Now let us print all the 2 digit numbers that are multiples of 3 or 5.
 
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''i = 0''' to '''i = 10'''
+
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''copyOf(marks, 5)''' to '''copyOf(marks, 3)'''
| style="border:1pt solid #000000;padding:0.097cm;"| So, '''i '''should have values from 10 to 99.
+
| style="border:1pt solid #000000;padding:0.097cm;"| Let us see what happens if we change the no.of elements to be copied.
 +
 
 +
 
 +
Let's'''Change 5''' to '''3'''.
  
  
So change''' i''' ''equal to'' '''0''' to '''i '''''equal to '''''10'''.
 
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''i<nowiki> < 10</nowiki>''' to '''i<nowiki> < 100</nowiki>'''
+
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''i '''''less than'' '''10''' to '''i '''''less than'' '''100'''.
+
| style="border:1pt solid #000000;padding:0.097cm;"| Save and Run 
 +
 
 +
As we can see, only the first three elements have been copied.
 +
 
 +
 
 +
Let us see what happens if the no.of elements to be copied is greater than the total no.of elements in the array.
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''System.out.println( i * i )''' to  
+
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''copyOf(marks, 3)''' to '''copyOf(marks, 8)'''
  
'''if ((i % 3 == 0) || (i % 5 == 0)){'''
 
  
'''System.out.println(i);'''
+
save and run. Point to output
 +
| style="border:1pt solid #000000;padding:0.097cm;"|So  Change '''3''' to '''8'''
  
'''}'''
 
| style="border:1pt solid #000000;padding:0.097cm;"| Delete '''System''' ''dot'' '''out''' ''dot'' '''println '''within brackets '''i''' ''into'' '''i'''.
 
  
 +
Save and Run the program
  
We print the number only if it is a multiple of 3 or 5.
 
  
 +
As we can see, the extra elements have been set to the default value, which is 0.
  
So type,
 
  
'''if '''within brackets '''i''' ''mod'' '''3''' ''double equal to'' '''0 '''or''' i '''''mod'' '''5 '''''double equal to '''''0'''.
+
Next we'll see how to copy a range of values.
  
 +
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Change '''copyOf(marks, 8)''' to '''copyOfRange(marks, 1, 4)'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"|So Change '''copyOf '''to''' copyOfRange '''and''' 8''' to '''1, 4'''
 +
 +
  This methods  copies all the elements starting from index 1 and stopping at index 3.
  
This statement checks whether '''i '''is divisible by '''3 '''or by '''5'''.
 
  
 +
  
Then, next line type '''System''' ''dot'' '''out '''''dot'' '''println''' within brackets '''i'''.
+
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Point to output.
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Save and Run 
  
 +
As we can see, the elements from index 1 to  3 have been copied.
  
Now, let us see the output.
 
  
 +
Note that we have given 1, 4  as our arguments
  
  
 +
But even, then the element at index 4 has not been copied.
 +
 +
 +
Only the elements till index 3 have been copied. It stops one elements before the gven range
  
 
|-
 
|-
| style="border:1pt solid #000000;padding:0.097cm;"| Save and run. Highlight the output
+
| style="border:1pt solid #000000;padding:0.176cm;"|  
| style="border:1pt solid #000000;padding:0.097cm;"| We can see that the numbers are either multiples of 3 or of 5.
+
| style="border:1pt solid #000000;padding:0.176cm;"| This behaviour ensures that continuity of ranges is maintained.
 +
 
 +
 
 +
(0, 4) implies from index 0 to index 3
 +
 
 +
(4, 6) implies from index 4 to index 5
 +
 
 +
 
 +
So it behaves as if (0, 4) + (4, 6) = (0, 5)
  
 
|-
 
|-
Line 208: Line 323:
  
 
'''Summary'''
 
'''Summary'''
| style="border:1pt solid #000000;padding:0.097cm;"| We have come to the end of this tutorial.  
+
| style="border:1pt solid #000000;padding:0.097cm;"|This brings us o the end of this tutorial.  
  
In this tutorial we have learnt how to '''use for loop in java.'''
+
In this tutorial we have learnt
  
|-
+
how to '''import the class Arrays'''.
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 7'''Assignment'''
+
| style="border:1pt solid #000000;padding:0.097cm;"| A three digit number is called Armstrong Number if it is equal to the sum of cubes of its digits.
+
  
 +
Perform array operations like  '''to strings''',sort fill.
  
For example, 153 is equal to 1 cube plus 5 cube plus 3 cube.
+
|-
 +
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 7'''Assignment'''
 +
| style="border:1pt solid #000000;padding:0.097cm;"| The assignment for this tutorial is,
  
  
Find all such 3 digit numbers.
+
Read about the Arrays.equals method and find out what is does.
  
 
|-
 
|-
Line 232: Line 348:
  
  
| style="border:1pt solid #000000;padding:0.097cm;"| To know more about the '''Spoken Tutorial''' project, watch the video available at the following link, that summarises the project.Alternatively, you can download and watch it.
+
| style="border:1pt solid #000000;padding:0.097cm;"| To know more about the '''Spoken Tutorial''' project, watch the video available at the following link, that summarises the project.
 +
 
 +
If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
Line 263: Line 381:
 
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 11'''About the contributor'''
 
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 11'''About the contributor'''
  
* This script has been contributed by '''TalentSprint'''
+
* This tutorial has been contributed by '''TalentSprint'''
 
* '''www.talentsprint.com'''
 
* '''www.talentsprint.com'''
  
Line 269: Line 387:
  
  
| style="border:1pt solid #000000;padding:0.097cm;"| This script has been contributed by '''TalentSprint'''.  
+
| style="border:1pt solid #000000;padding:0.097cm;"| This tutorial has been contributed by '''TalentSprint'''. Thanks for joining.
 
+
This is Prathamesh Salunke signing off.
+
 
+
Thanks for joining.
+
  
  

Latest revision as of 11:05, 10 May 2013

Title of script: Array Operations

Author: TalentSprint

Keywords: array operations, java, sort, fill, copy, video tutorial


Visual Cue Description
Slide 1

Welcome

Welcome to the spoken tutorial on Array Operations in java.
Slide 2

Learning Outcomes

In this tutorial, you will learn how to

import the class Arrays and,

perform basic operations on arrays.

Slide 3

Tools Used

For this tutorial we are using

Ubuntu 11.10,

JDK 1.6 and

Eclipse 3.7.0

Slide 4

Prerequisites

For this tutorial, you should have knowledge on arrays in Java.


If not, for relevant tutorial please visit our website which is as shown http://spoken-tutorial.org

Slide 5

import java.util.Arrays;

The methods for array operations are available in a class called Arrays.


To access them, we need to import that class.


It is done by the statement import java.util.Arrays;


We can access a method from the class.


We do it by adding a dot and the method name.


So Arrays dot toString means toString method from the Arrays class.

Point to the code


Minimize Slides and open Eclipse

{Eclipse should contain the following code}

public class ArraysDemo{

public static void main(String[] args){

}

}

Now Switch to eclipse.


We have already created a class ArraysDemo.


Let us now import the class Arrays.

Before the line public class..., type

import java.util.Arrays;

The import statement is written before the class definition.


So Before public class, type


import java.util.Arrays


This statement says that java contains a package called util which contains the class Arrays and it has to be imported.

Inside the main function, type

int marks[] = {2, 7, 5, 4, 8};

Now let us add an array.


Inside the main function,type


int marks open close square brackets equal to within brackets 2, 7, 5, 4, 8

In next line, type

String mStr = Arrays.toString(marks);


System.out.println(mStr);

Now we shall use a method available in the Arrays class to get a string representation of the array and print it.


SoType String mStr equal to Arrays dot toString Paranthesis inside Paranthesis will give the array name i.emarks semicolon.

Now this toString method gives a string representation of the array.


Now, we shall print the marks.


So, type System dot out dot println 'inside Paranthesis mStr semicolon.


Now let us look at the output so save and run the program

Save and run. Point to output As we can see int the output, the toString method has given a string representation of the array.


Now let us look at sorting the elements of the array.

Before the line Arrays.toString, type

Arrays.sort(marks);


Highlight sort.

So before the line Arrays dot toString within brackets marks type Arrays dot sort(marks);


The sort method in the Arrays class, sorts the elements of the array passed to it.


Now we are sorting the element of the array marks and then printing the string form of it.


Let us look at the output.So save and run

Save and run. Point to output As we can see in the output sort method has sorted to the array in the ascending order


Note that the sort method has changed the array itself.


This type of sorting is called inplace sorting.


It means the array which contains the elements is changed as a result of sorting.


The next method we are going to look at, is fill

Remove the line Arrays.sort and type

Arrays.fill(marks, 6);

The fill method takes two arguments.


Remove the sorting line and


Type Arrays dot fill within brackets the name of the arrays i.e marks;

This is our first argument and second is the value that should be felt in the array we will give it 6 and semicolon. Save and Run

Save and run. Point to output As we can see, as the name goes, the fill method fills the array with the given argument i.e 6


The next method we are going to look at, is copyOf

Remove the Arrays.fill.. line and type

int marksCopy[];

We are going to copy all the elements of the array marks into the array marksCopy

So remove arrays dot fill

And Type int marksCopy[];
In the next line, type


marksCopy = copyOf(marks, 5);


Change toString(marks) to toString(marksCopy)

next line,
Type marksCopy = copyOf(marks, 5);


This method takes two arguments.


The first argument is the name of the array from which you want to copy the elements.i.e marks

 the second is the no.of elements to copy overhere we will copy 5.

Then in arrays dot strings changes marks to marks copy



Save and run. Point to output Now save and run the program

We see that the elements of the array marks have been copied to the array marksCopy.



Change copyOf(marks, 5) to copyOf(marks, 3) Let us see what happens if we change the no.of elements to be copied.


Let'sChange 5 to 3.


Save and run. Point to output Save and Run

As we can see, only the first three elements have been copied.


Let us see what happens if the no.of elements to be copied is greater than the total no.of elements in the array.

Change copyOf(marks, 3) to copyOf(marks, 8)


save and run. Point to output

So Change 3 to 8


Save and Run the program


As we can see, the extra elements have been set to the default value, which is 0.


Next we'll see how to copy a range of values.

Change copyOf(marks, 8) to copyOfRange(marks, 1, 4) So Change copyOf to copyOfRange and 8 to 1, 4
 This methods  copies all the elements starting from index 1 and stopping at index 3.



Save and run. Point to output. Save and Run

As we can see, the elements from index 1 to 3 have been copied.


Note that we have given 1, 4 as our arguments


But even, then the element at index 4 has not been copied.


Only the elements till index 3 have been copied. It stops one elements before the gven range

This behaviour ensures that continuity of ranges is maintained.


(0, 4) implies from index 0 to index 3

(4, 6) implies from index 4 to index 5


So it behaves as if (0, 4) + (4, 6) = (0, 5)

Minimize the Eclipse window and switch to slides.


Slide 6

Summary

This brings us o the end of this tutorial.

In this tutorial we have learnt

how to import the class Arrays.

Perform array operations like to strings,sort fill.

Slide 7Assignment The assignment for this tutorial is,


Read about the Arrays.equals method and find out what is does.

Slide 8About the Spoken Tutorial Project
  • It summarises the Spoken Tutorial project
  • If you do not have good bandwidth, you can download and watch it


To know more about the Spoken Tutorial project, watch the video available at the following link, that summarises the project.

If you do not have good bandwidth, you can download and watch it.

Slide 9Spoken Tutorial WorkshopsThe Spoken Tutorial Project Team
  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test


The Spoken Tutorial Project Team. Conducts workshops using spoken tutorials and gives certificates for those who pass an online test. For more details, please write to contact AT spoken HYPHEN tutorial DOT org.
Slide 10Acknowledgement
  • Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at


Spoken Tutorial Project is a part of the Talk to a Teacher project and is supported by the National Mission on Education through ICT, MHRD, Government of India. More information on this Mission is available at spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro
Slide 11About the contributor
  • This tutorial has been contributed by TalentSprint
  • www.talentsprint.com
  • Thanks for joining


This tutorial has been contributed by TalentSprint. Thanks for joining.



Contributors and Content Editors

Arya Ratish, Pratham920, Sneha