Skip to content
Advertisement

Tag: copy

Java, my own copy() method would not work

I am learning java and came upon a small problem, my copy() method will not work. I work based on a UML diagram and I am pretty sure that I’m doing everything correctly. Here is the code: Constructor: copy() method: The error flashes at the parantheses FileName() it says: ‘FileName(java.lang.String, java.lang.String)’ in ‘Exam_Practice_4.FileName’ cannot be applied to ‘()’ Here is

Dividing a 1D array into a 2D array

So I have homework that asked me to: Write a method that takes two parameters: an array of integers and an integer that represents a number of elements. It should return a two-dimensional array that results from dividing the passed one-dimensional array into rows that contain the required number of elements. Note that the last row may have less number

How to copy a java.util.List into another java.util.List

I have a List<SomeBean> that is populated from a Web Service. I want to copy/clone the contents of that list into an empty list of the same type. A Google search for copying a list suggested me to use Collections.copy() method. In all the examples I saw, the destination list was supposed to contain the exact number of items for

How to make a copy of ArrayList object which is type of List?

I studied that Java passes object references by value, and in order to make a local copy of an object I can either do clone() or copy-constructor. I also looked at deep/shallow copy as well as several posts on Stack Overflow. I am looking at this example: Only a few articles I read mention that ArrayList implements cloneable, but does

Eclipse copy/paste entire line keyboard shortcut

Anyone know the keyboard shortcut to copy/paste a line into a new line in Eclipse, without having to highlight the entire line? ctrl-alt-down turns my whole screen upside down (I’m on windows). Interestingly, that’s what’s specified in the windows->preferences. Answer Ctrl-Alt-Down: copies current line or selected lines to below Ctrl-Alt-Up:: copies current line or selected lines to above Ctrl-Shift-L: brings

How do I copy an object in Java?

Consider the code below: So, I want to copy the dum to dumtwo and change dum without affecting the dumtwo. But the code above is not doing that. When I change something in dum, the same change is happening in dumtwo also. I guess, when I say dumtwo = dum, Java copies the reference only. So, is there any way

Advertisement