Copying objects

Hi!
How can I make a copy of an object? I've posted this problem yet another time, but the answers didn't work...
I only want to copy an array x into an array y and the possibility to change x without changing y at the same time (=> without referencing):
source:
int x[]={1,2,3,4,5};
int y[]= new int[5];
y=x; //A
for (int i=0;i<5;i++) System.out.print(x); //1 2 3 4 5
for (int i=0;i<5;i++) System.out.print(y[i]); //1 2 3 4 5
x[0]=0; x[1]=0; x[2]=0; x[3]=0; x[4]=0; //C
for (int i=0;i<5;i++) System.out.print(x[i]); //0 0 0 0 0
for (int i=0;i<5;i++) System.out.print(y[i]); //0 0 0 0 0
With this code, I get a reference for x in y (A), so when I change the values of x (C) the values of y are also changed.
How can I get a COPY of x into y? I've tried it with "int y[]=x", but this also doesn't work. By the way, the assignment should be in a loop, so initializing for copying isn't good...
Thanks! Chris

I think this might help you people. There is a concept called deep copy. This does not reference as you people have problem. This works on any object, but The only requirement is that the object in question should be serializable.. As for as any object[] (arrays) take each object from the array and deep copy it and put in the new array.
// this is  a static method to make a deep copy of any object.
   public static Object deepCopy(Object oldObj) throws Exception
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
      try
         ByteArrayOutputStream bos =
               new ByteArrayOutputStream(); // A
         oos = new ObjectOutputStream(bos); // B
         // serialize and pass the object
         oos.writeObject(oldObj);   // C
         oos.flush();               // D
         ByteArrayInputStream bin =
               new ByteArrayInputStream(bos.toByteArray()); // E
         ois = new ObjectInputStream(bin);                  // F
         // return the new object
         return ois.readObject(); // G
      catch(Exception e)
         System.out.println("Exception in ObjectCloner = " + e);
         throw(e);
      finally
         if(oos != null)
           oos.close();
        if(ois != null)
         ois.close();
}Enjoy coding in Java. Java never sucks.

Similar Messages

  • Copying objects from Illustrator CS3 to FreeHand 11.0.2

    Working on a Mac in OSX 10.4.11, I was able to select and copy objects in an open Illustrator CS2 file and paste them into an open FreeHand 11.0.2 file, where they would be fully editable. After migrating to OSX 10.6.2 and upgrading to CS3, this no longer works - the objects selected and copied from Illustrator either do not appear (only corner indicators are visible) or a pale version appears as an uneditable low-rez image with funny colors....
    Because there are so many missing features in Illustrator, it's important for me to be able to work back and forth between the two apps.  Has anyone been able to achieve this (formerly) simple interactivity?

    I got the following post from Danny Haas:
    If you go to Edit>Special>Paste Special and then select AI/EPS from the list
    it should paste just fine. It works well for me.
    Worked for me too, although text was not imported as editable text.  To do
    that had to special paste the text separately as unformatted text, and then
    reformat in FH.
    From: Judy_Arndt <[email protected]>
    Reply-To: <[email protected]>
    Date: Wed, 13 Jan 2010 17:19:27 -0700
    To: PETER AGOOS <[email protected]>
    Subject: Copying objects from Illustrator CS3 to FreeHand 11.0.2
    I skipped AICS3, but now use AICS4 for some tasks.
    The only solution I've found is to save the AI CS4 file as AI 8, open that
    in FHMX and copy from there.

  • How to copy objects from Pages (5.5.1) and paste it into Photoshop as a vector smart object with high resolution?

    I recently have bought a new Macbook Pro (Version 10.10.1) with the OS X Yosemite. The computer comes with the new Pages (version 5.5.1).
    Here is the problem: I like to create artwork using the shapes on Pages. Previously, on my old mac, I used Pages 4.3 to create objects, which I would copy then paste to Photoshop and it would become a vector smart object. However, in the new Pages (version 5.5.1), when I copy objects, they would appear on Photoshop as instead, a layer and it would not be in full resolution.
    Also, I know there is nothing wrong with the Pages file itself because I have converted the document to PDF form and it is high resolution when inserted into Photoshop that way.
    Does anyone know how I can copy individual objects from Pages (5.5.1) and paste it into Photoshop as a vector smart object with high resolution as I have done before?
    Thanks!

    ghotiz wrote:
    copy the image and have it in a high-quality PNG format that does not include the background from the Pages document.
    Oh, well if you don't actually need vector objects then it looks like this is possible. As I said earlier, Pages is putting a PNG on the clipboard. I tested it and it does paste into Photoshop as a transparent layer, because I can see the transparent background of the pasted PNG graphic if I either turn off all layers behind it in Photoshop, or if I start a new Photoshop document to paste into but make sure I choose Transparent for the Background Contents in the New Document dialog.

  • I intermittently cannot option+drag shapes, or even drag a copied object. Instead Illustrator will try to enact re-sizing or rotation.

    This is so frustrating, having never had this issue in any prior versions of illustrator.
    I'm using Illustrator CC, on a Macbook Pro Retina (newest), on OSX 10.10.2 ... using the trackpad for now in lieu of my tablet or mouse (suspecting that this might be the issue).
    As I said in the title, very frequently, I'll go to option+drag an object to copy it and instead of it dragging out a new copy, it tries to either rotate or stretch the object instead. This is in every different file I try to work on. I'll try to do it the old fashioned way of cmd+C, cmd+F and then dragging it, but this too seems to run into the same issue. Dragging the newly copied object instead enacts rotation or stretch tools.
    I'm sure you can appreciate how maddening this can be if you're accustomed to quickly multiplying lots of little objects on screen.
    Thanks!

    jomo,
    We have had a few similar threads recently, active at the same time:
    Re: Illustrator thinks I want to resize an object...
    I have issues while trying to drag/alt+drag a relatively small odject.

  • XI/PI: Integration Repository- copy object options meaning?

    Hi All,
    When we copy objects within IR we get follwing two options,
    1. With all dependents objects
    2. Save original as reference
    can anyone tell me implications of chosing these options?
    why and when should we chose them?
    Thanks and Regards,
    Ujwal

    >>1. With all dependents objects
    When u copy Mesage Type, it's dependent object Data type is also copied.. similarly Interface Mapping will copy Message Mapping also.. this is applicable for all IR obects that are dependent...
    >>2. Save original as reference
    The copied obects that are there in the new Namespace will refer to it's dependen't objects that is there in the original/initial namespace...
    >>can anyone tell me implications of chosing these options?
    >>why and when should we chose them?
    depend's... if the initial/original namespace are not going to be moved to other box and only the new namespace is to be moved then even the dependent objects should be copied to the new namespace....
    ~SaNv...

  • Trying to copy object bus1001006

    I am trying to crate a workflow for material change for that I need to copy object BUS1001006 while creating a container , I am getting an error message staying ‘Object type 'ZRSP1001' is not defined’ please guide me what could be cause of it

    I am not 100% what you are trying to achieve, but check these:
    1) Is ZRSP1001 a subtype for object BUS1001006
    2) have you delegated ZRSP1001 to BUS1001006
    3) have you changed the status of your custom object's attributes/methods to "imlemented"
    4) have you generated your custom object ZRSP1001
    All these steps can be done in transaction SWO1. If your aim is not to "replace" the standard BUS1001006 with your custom object in your workflow, you can skip steps 1) and 2). If your aim is to "replace", then check all the steps mentioned above, and then you should be able to use the standard BUS1001006 when defining the data types of your container elements in your workflow.

  • Copy object with clipping mask from illustrator to photoshop

    I want to copy objects from illustrator to use in photoshop, but the eps file that i am working in has a clipping mask and when i attempt to copy objects in that file from illustrator 6 to photoshop 6, portions (in some cases) all of the object turns black or gray.  I'm sure this is a simple noob error (hope my question is clear enough), and it's driving me nuts.  I have searched for solutions using terms "clipping mask, black, copy, move, illustrator, photoshop, etc." and can't find any discussions on this topic.  Can you please help?
    Here are the print screens to show you what i get in ai and ps -
    (see blue outlined oval object selected - opaque white gradient)
    (when moved to ps, opaque whitish oval turns black)
    I'm such a noob!  Thanks in advance for your help!

    You simply lose the blending modes and transparency settings because this stuff works differently in both programs. You will have to reinstate it manually e.g. if the white highlight is created usuing Add blending mode, you will ghave to use the same in PS...
    Mylenium

  • Illustrator CC pastes unformatted code when trying to copy objects

    When I attempt to copy and paste objects or text, illustrator pastes unformatted code (see picture).
    When I copy the object and paste it a second time, it works fine, it's only when pasting for the first time.
    It's not the end of the world but it's really quite annoying, any help would be appreciated, cheers.
    Image below shows the copied objected and resulting paste

    just fixed my own problem: preferences > file handling & clipboard > include SVG code
    simple

  • Copy Objects

    I am sure every one of you would have come across this type of code. We copy objects from Domain to application layer or from Data layer to business layer.
    They are mere copy and if the DO's , BO's are long, we ahve to write so many methods like convertToDomain object etc. I am wondering if there is a pattern that we could apply to handle this generically.
    One of the thing I am thinking of is to use reflection to copy object of similar type. For eg. PersonDO might have age, name and DOB, and PersonBO might have just name and DOB. Would it not be a good idea to copy over from PersonDO to PersonBO provided all variables match using reflection. It might sound dumb. But I don't like the various copy that we do, it literally fills up the java file.
    Any thoughts would be helpful.
    thanks
    --

    There is one pattern which I had developed for some same scenario.
    What you can do is that use the custom annotation to copy the fields from one object to another.
    Here is the example:
    Create a Custom Annotation:
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.FIELD})
    public @interface MyField {
    String name();
    ClassA {
    @MyField(name="CopyName")
    private String name;
    @MyField(name="CopyAge")
    private int age;
    ... getters and setters goes here
    ClassB{
    @MyField(name="CopyName")
    private String myName;
    @MyField(name="CopyAge")
    private int currentAge;
    Now you can copy the two different class based on the annotation using the reflection like this
    public void copyAtoB (ClassA objA, ClassB objB) {
    Field fields[] = objB.getClass().getDeclaredFields();
    for (Field f : fields) {
    Column annot = f.getAnnotation(MyField.class);
    if (annot != null) {
    Object tempobj = getValueFromObjectA(objA, f.getType(), annot.name()); // Needs to be implemented in same manner.
    String fieldName = f.getName();
    fieldName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    Method method = objB.getClass().getMethod(fieldName, f.getType());
    if (f.getType() == int.class) {
    method.invoke(objB, ((Integer) tempobj).intValue());
    } else {
    method.invoke(objB, tempobj);
    Note: Annotation name should be same for the fields which you want to copy.

  • Internal lock version management : Unable to copy objects

    Hi ALL
    We need help with this particular problem we are facing with our ID objects....
    I am unable to copy my communication channels which i was able to do it earlier without any problem...just to make it easy while developing new object...we used to make a copy and edit...instead of creating new scratch.
    However, now we are facing a problem once we try activating any copied object, here is the error message we are getting...
    "Version management was unable to execute the last action because a temporary internal lock has been set. Repeat the action "
    This is not a user lock....we checked that, please do let us know how we can fix this ...so that we may be able to copy and activate copied object without the above error.
    Your help is greatly appreciated!!
    Thank you,
    Partrick

    Hi
    Its Weird but it can happen if you copy object whose previous version is still not activated. I still think you must check with all the change lists. or bring all to PISUPER and activate them.
    Oops then i think it got locked for all. Refresh the cache and even soft restart for J2EE.
    I think you copy a lot
    Thanks
    Gaurav
    Edited by: Gaurav Bhargava on Dec 17, 2008 1:38 AM

  • Trying to copy and paste objects in keynote 6 I only get a hyperlink when pasting. Anyone else having the same problem? is there anywhere I can change it so that the copied object is pasted directly into the new slide?

    Hi
    I am trying to copy one object from one lside to another slide in the same presentation. The only thing I get when pasting is a hyperink. Does anyone know how I can turn this off so that the image or the object is pasted as copied to the new slide?
    Thanks a lot

    there are some unexpected issues when copy and pasting.
    As a workaround, use duplicate slide to get the same object in another slide, (select the slide in navigator and command D or right click > duplicate)

  • [SOLVED] Problem copying objects in Inkscape 0.48.0-4

    I have problems when I copy any object when using inkscape. Even after removing the config directories and using a completely blank document.
    I create a simple rect and press ctr+c (or use the context menu) and this error comes up:
    El script inkex.py y, por lo tanto, esta extensión necesitan la envoltura lxml («lxml wrapper») para libxml2. Descargue
    e instale la última versión de http://cheeseshop.python.org/pypi/lxml/ o mediante su gestor de paquetes con un
    comando similar a este: sudo apt-get install python-lxml
    It says "inkex.py", which comes with the package, needs python-lxml. So I install the package, close inkscape, remove the configuration directories and try again.
    Now it throws this error message:
    No matching node for expression: /svg:svg/@sodipodi:docname
    Traceback (most recent call last):
    File "gimp_xcf.py", line 185, in <module>
    e.affect()
    File "/usr/share/inkscape/extensions/inkex.py", line 215, in affect
    self.effect()
    File "gimp_xcf.py", line 43, in effect
    docname = self.xpathSingle('/svg:svg/@sodipodi:docname')[:-4]
    TypeError: 'NoneType' object is not subscriptable
    The script "gimp_xcf.py" also comes with the package. No clue why it is calling it since I'm only trying to copy (not even paste) from a clean svg document.
    I click accept and this error message comes up asking me to install uniconvertor:
    You need to install the UniConvertor software.
    For GNU/Linux: install the package python-uniconvertor.
    For Windows: download it from
    http://sk1project.org/modules.php?name=Products&product=uniconvertor
    and install into your Inkscape's Python location
    I install uniconvertor, delete the configuration directories and try again. The previous "gimp_xcf.py" error message comes up, I click accept again only to get another error dialog:
    No layers found
    I click accept again and now I can paste the object. But the "gimp_xcf.py" and "No layers found" dialogs keep coming up in a loop which can only be stopped by killing inkscape.
    I doubt very much this is a upstream issue since I couldn't find it in inkscape's bug tracker (such obvious bug would have been reported already) I also cannot find any report in arch's bug tracker. So I'm unsure if I should report this, anyone else has this problem? All related packages are up to date.
    Last edited by dresb (2011-02-07 16:21:08)

    I found I was having this problem running xfce4.8
    There seems to be some talk about it here https://bugs.launchpad.net/inkscape/+bug/418242
    It seems that clipboard managers may be causing the problem. I wasn't running xfce4-clipman but I found that killing xfce4-settings-helper fixed the problem for me.
    Hope this helps.

  • How do I copy objects from a flash shared library?

    I'm a total beginner at Flash and I've been given the task of creating a new version of a flash component we use in house. The current version uses a shared library of objects in a separate .swf file.
    One of my tasks is to copy the items from the shared library into this new version so only the one .swf file is needed for everything to work. I've figured out how to unlink items in the new version from the shared library but that doesn't seem to copy them into the new version. can someone tell me how to do the copying bit please? I'm using Flash CS3.

    Drag it to the computer’s internal drive and then to the library in the open iTunes application window.
    (114990)

  • Copying objects from InDesign to paste into Photoshop: new file always defaults to 72 dpi.  How do I fix this?

    In previous versions, you could copy and object in another piece of software and Photoshop would automatically size the new file to take the object at 300 dpi.  In CS this appears not to be the case, the default size being 72 dpi.  How do I fix this? 

    Please refer PS system requirements from this link:
    http://helpx.adobe.com/photoshop/system-requirements.html#Photoshop CC system requirements/
    Regards,
    Ashutosh

  • Copying Objects One Project to Another

    I am trying to copy some obejcts from one project to another.
    Both files are version 2. I select import, then from the filmstrip
    I clear all, then select objects only, then tell it wht slide I
    want them on. It acts like it's working, but noting happens. The
    object don't show up.
    Any insight is appreciated.
    Bill

    As we both have found out, no question is a silly one. I have
    one click box, one highlight, and a text caption. I am creating a
    simulation for a 1st level manager. When I create the sim for teh
    2nd level manager the backgrounds are different but the same object
    apply. Rather than create the click, highlight and captions all
    over, I wanted to use the import feature. It just made sense. I'll
    give ADOBe a call and see if they know of any work around.
    One thing I did notice, when I do try and import the objects
    to a slide I get a very fast progress indicator. The objects do not
    appear on the slide. Then if I go to exit it tells me the project
    was changed and I need to save it. The when I do save it takes 4-6
    miutes to save. Odd becasue no changes are visible.

Maybe you are looking for