Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Copy one array from another in Java

public class Demo {
	public static void main(String[] args) {
		String[] arr = new String[] { "P","Q", "R", "S", "T"};
		System.out.println("Initial array...");
		for (int i = 0; i<arr.length; i++)
			System.out.println(arr[i]);
			int len = arr.length;
			String[] arr2 = new String[len];
			System.arraycopy(arr, 0, arr2, 0, arr.length);
			System.out.println("New array...copied");
			for (int i = 0; i<arr2.length; i++)
				System.out.println(arr2[i]);
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.