Home > Java > javaTutorial > Java Example - Array Expansion

Java Example - Array Expansion

黄舟
Release: 2017-02-18 10:14:05
Original
1944 people have browsed it

The following example demonstrates how to expand the array after the array is initialized:

/*
 author by w3cschool.cc
 文件名:Main.java
 */public class Main {
   public static void main(String[] args) {
      String[] names = new String[] { "A", "B", "C" };
      String[] extended = new String[5];
      extended[3] = "D";
      extended[4] = "E";
      System.arraycopy(names, 0, extended, 0, names.length);
      for (String str : extended){
         System.out.println(str);
      }
   }}
Copy after login

The output result of running the above code is:

A
B
C
D
E
Copy after login

The above is the Java example - array expansion. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template