Why has changed both sides of equation in java?

Arman

I have a strange problem that confused me completely.

I am using WEKA for my project, and I want to change class values of my dataset to test somethings; so I preserve my dataset into another value whose name is d, and using setClassValue method for changing class values. Finally, I print classValues for each instance in d and dataset variables.

Instances d=dataset;
for (int i = 0; i <dataset.size(); i++) {
    dataset.get(i).setClassValue(10);
    System.out.println(dataset.get(i).classValue()+ "\t" +d.get(i).classValue() );
}

Result is not believable, both d and dataset class values were changed. Why did this happen? How can I change class values of a dataset with considering that I should preserve my original dataset?

SLaks
d=dataset

You now have two variables that both refer to the same object.

Unlike C++, Java never implicitly copies anything.
If you want a separate copy of an object, you need to make one yourself.

If the object implements Cloneable, you can do that using clone().

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Does Entity Framework need associations on both sides?

분류에서Dev

record audio on Linux - capture both sides of a VoIP conversation

분류에서Dev

Check if a file has been changed

분류에서Dev

Java Applet Changed With Paint

분류에서Dev

Why cant both my client communicate to each other? (java server socket)

분류에서Dev

Why does Skype obsolete so many Java packages and how can I have both?

분류에서Dev

What has changed my mouse selection behaviour?

분류에서Dev

Has SQL changed very much from 2011

분류에서Dev

Why both of if statements are executed no matter what the input is?

분류에서Dev

Why does AbstractCollection implement both Iterable and Collection?

분류에서Dev

Notify all components that authentication has been changed in Blazor

분류에서Dev

Num Lock function has changed after upgrading to UBUNTU 13.10

분류에서Dev

django apps and models.py in 1.7 - what exactly has changed?

분류에서Dev

Notify Qt Window when its visibility status has changed

분류에서Dev

SSH error: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

분류에서Dev

Why Java's String has the method length() rather than property length (like an array?)

분류에서Dev

this.redirect and Router.go both error with 'has no method'

분류에서Dev

Highlight click event with Table that has both row and column spans

분류에서Dev

Is there a way to check if java object changed after submit

분류에서Dev

Why ServiceStack MvcHtmlString has no namespace

분류에서Dev

Why view.onLayout() is called repetitively when changed=false?

분류에서Dev

Why did Outlook create an .ost file when I changed ISP?

분류에서Dev

why the last element of array changed after 2 foreach loop?

분류에서Dev

Why are both gnome-software and the update-manager installed on 16.04?

분류에서Dev

Given a program that has both 32 and 64bit variant, how do I put them both in my PATH with different names?

분류에서Dev

Transcendental Equation

분류에서Dev

Can rsync update a large file that has only changed partially without full retransmission?

분류에서Dev

How to Fix 'The model backing the context has changed since the database was created.' in database first

분류에서Dev

How to resolve issue --- Element not found in the cache - perhaps the page has changed since it was looked up

Related 관련 기사

  1. 1

    Does Entity Framework need associations on both sides?

  2. 2

    record audio on Linux - capture both sides of a VoIP conversation

  3. 3

    Check if a file has been changed

  4. 4

    Java Applet Changed With Paint

  5. 5

    Why cant both my client communicate to each other? (java server socket)

  6. 6

    Why does Skype obsolete so many Java packages and how can I have both?

  7. 7

    What has changed my mouse selection behaviour?

  8. 8

    Has SQL changed very much from 2011

  9. 9

    Why both of if statements are executed no matter what the input is?

  10. 10

    Why does AbstractCollection implement both Iterable and Collection?

  11. 11

    Notify all components that authentication has been changed in Blazor

  12. 12

    Num Lock function has changed after upgrading to UBUNTU 13.10

  13. 13

    django apps and models.py in 1.7 - what exactly has changed?

  14. 14

    Notify Qt Window when its visibility status has changed

  15. 15

    SSH error: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

  16. 16

    Why Java's String has the method length() rather than property length (like an array?)

  17. 17

    this.redirect and Router.go both error with 'has no method'

  18. 18

    Highlight click event with Table that has both row and column spans

  19. 19

    Is there a way to check if java object changed after submit

  20. 20

    Why ServiceStack MvcHtmlString has no namespace

  21. 21

    Why view.onLayout() is called repetitively when changed=false?

  22. 22

    Why did Outlook create an .ost file when I changed ISP?

  23. 23

    why the last element of array changed after 2 foreach loop?

  24. 24

    Why are both gnome-software and the update-manager installed on 16.04?

  25. 25

    Given a program that has both 32 and 64bit variant, how do I put them both in my PATH with different names?

  26. 26

    Transcendental Equation

  27. 27

    Can rsync update a large file that has only changed partially without full retransmission?

  28. 28

    How to Fix 'The model backing the context has changed since the database was created.' in database first

  29. 29

    How to resolve issue --- Element not found in the cache - perhaps the page has changed since it was looked up

뜨겁다태그

보관