ChapterSixPartIII

ChapterSixPartIII - IT 108 Arrays Part III George Mason University Copying Arrays Often in a program you need to duplicate an array or a part of an

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
IT 108 Arrays Part III George Mason University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copying Arrays Often, in a program, you need to duplicate an array or a part of an array. In such cases you could attempt to use the assignment statement (=), as follows: list2 = list1; Contents of list1 list1 Contents of list2 list2 Before the assignment list2 = list1; Contents of list1 list1 Contents of list2 list2 After the assignment list2 = list1; Garbage
Background image of page 2
Copying Arrays Using a loop: int[] sourceArray = {2, 3, 1, 5, 10}; int[] targetArray = new int[sourceArray.length]; for (int i = 0; i < sourceArrays.length; i++) targetArray[i] = sourceArray[i];
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The arraycopy Utility arraycopy(sourceArray, src_pos, targetArray, tar_pos, length); Example: System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length); Need to: import java.util.*;
Background image of page 4
New Features in Java 1.5 Scanner Printf Autoboxing Enumerated Types Foreach loop construct (Enhanced for loop) Generic Types
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Enhanced for Loop JDK 1.5 introduced a new for loop that enables you to traverse the complete array
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/26/2012 for the course IT 108, 103, taught by Professor Bruno during the Spring '11 term at George Mason.

Page1 / 10

ChapterSixPartIII - IT 108 Arrays Part III George Mason University Copying Arrays Often in a program you need to duplicate an array or a part of an

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online