Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 289407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:54:15+00:00 2026-05-12T05:54:15+00:00

java.util.Calendar.clone() returns …a new Calendar with the same properties and returns a shallow copy

  • 0

java.util.Calendar.clone() returns “…a new Calendar with the same properties” and returns “a shallow copy of this Calendar”.

This does not appear to be a shallow copy as answered here on SO. That question is tagged language-agnostic, Java does not seem to follow the language agnostic definition. As I step through the code I notice that the structure and the elements are copied to this new object, more than the language agnostic structure only.

In Java, what is a shallow copy?

How does it differ from a Java deep copy (if that exists)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:54:15+00:00Added an answer on May 12, 2026 at 5:54 am

    A shallow copy just copies the values of the references in the class. A deep copy copies the values. given:

    class Foo {
      private Bar myBar;
      ...
      public Foo shallowCopy() {
        Foo newFoo = new Foo();
        newFoo.myBar = myBar;
        return newFoo;
      }
    
      public Foo deepCopy() {
        Foo newFoo = new Foo();
        newFoo.myBar = myBar.clone(); //or new Bar(myBar) or myBar.deepCopy or ...
        return newFoo;
      }
    }
    
    Foo myFoo = new Foo();  
    Foo sFoo = myFoo.shallowCopy();  
    Foo dFoo = myFoo.deepCopy();  
    
    myFoo.myBar == sFoo.myBar => true  
    myFoo.myBar.equals(sFoo.myBar) => true  
    myFoo.myBar == dFoo.myBar => **false**  
    myFoo.myBar.equals(dFoo.myBar) => true  
    

    In this case the shallow copy has the same reference (==) and the deep copy only has an equivalent reference (.equals()).

    If a change is made to the value of a shallowly copied reference, then the copy reflects that change because it shares the same reference. If a change is made to the value of a deeply copied reference, then the copy does not reflect that change because it does not share the same reference.

    C-ism

    int a = 10; //init
    int& b = a; //shallow - copies REFERENCE
    int c = a;  //deep - copies VALUE
    ++a;
    

    Result:

    a is 11  
    *b is 11  
    c is 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 194k
  • Answers 194k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Maybe this? class Log: BAT_STATS = ['AB', 'R', 'H', 'HR']… May 12, 2026 at 6:47 pm
  • Editorial Team
    Editorial Team added an answer Two problems with your statement: You're not selecting email to… May 12, 2026 at 6:47 pm
  • Editorial Team
    Editorial Team added an answer Are you using DBIx::Class? The basic idea here applies even… May 12, 2026 at 6:47 pm

Related Questions

java.util.Calendar.clone() returns ...a new Calendar with the same properties and returns a shallow copy
In java.util.Calendar , January is defined as month 0, not month 1. Is there
I'm trying to change default firstDayOfWeek for java.util.Calendar from SUNDAY to MONDAY. Is it
The database has data in UTC and when I try to get data java.util.Calendar
I am looking for some subclasses of the Java calendar class, preferably a Hijri

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.