package com.Test.Demo.Test;
import java.util.Arrays;
public class CopyTest {
public static void main(String[] args){
Book[] b1 ={new Book("asd",12),new Book("qwe",90)};
Book[] b2 =b1.clone();
Book[] b3=new Book[3];
System.arraycopy(b1,0,b3,1,1);
Book[] b4= Arrays.copyOf(b1,2);
Book[] b5= Arrays.copyOfRange(b1,1,2);
for(int i=0;i<b2.length;i++){
System.out.println(b2[i]);
}
for(int i=0;i<b3.length;i++){
System.out.println(b3[i]);
}
for(int i=0;i<b4.length;i++){
System.out.println(b4[i]);
}
for(int i=0;i<b5.length;i++){
System.out.println(b5[i]);
}
}
}
class Book implements Cloneable{
private String name;
private int title;
public Book(){
}
public Book(String name, int title) {
this.name = name;
this.title = title;
}
public String getName() {
return name;
}
public int getTitle() {
return title;
}
public void setName(String name) {
this.name = name;
}
public void setTitle(int title) {
this.title = title;
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public String toString() {
return "Book{" +
"name='" + name + '\'' +
", title=" + title +
'}';
}
}