Array copy method : System Class « Development « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. JSP
22. JSTL
23. Servlet
24. Web Services SOA
25. Email
26. J2ME
27. J2EE Application
28. XML
29. Design Pattern
30. Log
31. Security
32. Apache Common
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Development » System Class 
6. 1. 6. Array copy method

Copy the content of an array (source) to another array (destination), beginning at the specified position, to the specified position of the destination array.

public static void arraycopy (Object source, int sourcePos, Object destination, int destPos, int length)

For example, the following code uses arraycopy to copy the contents of array1 to array2.

public class MainClass {

  public static void main(String[] a) {
    int[] array1 = 123};
    int[] array2 = new int[array1.length];
    System.arraycopy(array1, 0, array2, 0, array1.length);

    for(int i: array2){
      
      System.out.println(i);
    }
  }
}
1
2
3
4
6. 1. System Class
6. 1. 1. java.lang.System
6. 1. 2. PrintStream has many print method overloads that accept different types
6. 1. 3. println adds a line terminator at the end of the argument
6. 1. 4. The err field represents a PrintStream object
6. 1. 5. The 'in' field represents the standard input stream
6. 1. 6. Array copy method
6. 1. 7. Terminates the running program and the current JVM
6. 1. 8. Returns the computer time in milliseconds
6. 1. 9. public static long nanoTime(): provide more precision, i.e. in nanoseconds
6. 1. 10. Using System.getProperty(String key) to retrieve system properties
6. 1. 11. Create a user-defined property or change the value of the current property
6. 1. 12. Returns a default value if the specified property does not exist
6. 1. 13. Returns all system properties
6. 1. 14. Redirect the output of System.out to a file.
w___w__w_.___j__a_v_a_2___s__.__c___om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.