?
Solved

Creating sub-array

Posted on 2008-11-16
2
Medium Priority
?
14,209 Views
Last Modified: 2013-11-23
Is it possible to create a sub-array from an array directly without having to copy the elements?

Let's say that I have an array of length 1000, and I want to create an array from index 0 to index 400.

Without having to copy each element into a new array, can I do something like int [] newArray = oldArray(startIndex, endIndex)?

0
Comment
Question by:ubuntuguy
  • 2
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 22972195
No - you need to copy it
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 22972223
//I want to create an array from index 0 to index 400



int[] newArray = new int[401];
System.arrayCopy(oldArray, 0, newArray, 0, newArray.length);

Open in new window

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question