Answers for "clone rarray list java"

0

ArrayList clone() method in java

import java.util.ArrayList;
public class ArrayListCloneMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<String> al = new ArrayList<String>();
      al.add("violet");
      al.add("indigo");
      al.add("blue");
      al.add("green");
      al.add("yellow");
      System.out.println("ArrayList before using clone() method: " + al);
      // create another ArrayList and copy
      ArrayList<String> arrClone = new ArrayList<String>();
      arrClone = (ArrayList)al.clone();
      System.out.println("ArrayList after using clone() method: " + arrClone);
   }
}
Posted by: Guest on October-30-2020
0

how to clone array in java

// A Java program to demonstrate array copy using clone()
public class Test {
    public static void main(String[] args)
    {
        int a[] = { 1, 8, 3 };
        int b[] = a.clone();
    }
}
Posted by: Guest on March-18-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language