-2

I am having two models. One is Model A and another is Model B. Both models have getter-setter. But only model A holds value and Model B is totally empty. I want to use Model A and set all those values in model B. How to do that??

In Model A:

public void setVideoUrl(String videoUrl){this.videoUrl = videoUrl;}
public String getVideoUrl(){return videoUrl;}

In Model B:

public String getVideoUrl() {
    return videoUrl;
}

public void setVideoUrl(String videoUrl) {
    this.videoUrl = videoUrl;
}

In Model A "videoUrl" is already set. I want to set that same "videoUrl" in model B. How to do it??

  • 1
    Possible duplicate of [Copy all values from fields in one class to another through reflection](https://stackoverflow.com/questions/1667854/copy-all-values-from-fields-in-one-class-to-another-through-reflection) – TalkLittle Jul 03 '17 at 15:55

2 Answers2

1

Create an instance of Model B and get the video URL from Model A and set it to Model B.

ModelA modelA = new ModelA();
modelA.setVideoUrl("YOUR_URL");


ModelB modelB = new ModelB();
modelB.setVideoUrl(modelA.getVideoUrl());
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
0
modelB.setVideoUrl(modelA.getVideoUrl());
Shubham Goel
  • 1,962
  • 17
  • 25