Skip to content

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 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: DummyBean dum = new DummyBean(); dum.setDummy(“foo”); System.out.println(dum.getDummy()); // prints ‘foo’ DummyBean dumtwo = dum; System.out.println(dumtwo.getDummy()); // …