This question already has answers here:
Java ArrayList copy
(10 answers)
Closed 6 years ago.
I have two ArrayList variables
first
ArrayList listOrders;
the second is
ArrayList selectedOrders = listOrders;
The problem is when i deleting listOrders it's clear selectedOrders value.
Is there a way to store value after deleting his parent?
If you want to hold 2 different references with the same data do:
ArrayList selectedOrders = new ArrayList<>(listOrders);
Related
This question already has answers here:
Java ArrayList to Kotlin Array
(4 answers)
Closed 1 year ago.
So, I try to make a line chart using AAChartModel. I have ArrayList in my code. But in AAchartModel they used an arrayOf instead of ArrayList.
So My Question is, how do I convert from ArrayList to arrayOf ?
arrayOf() returns just an Array. So you can call arrayList.toTypedArray()
This question already has answers here:
How to use subList()
(6 answers)
Closed 3 years ago.
I want to pass an array as argument to a function without first element.
I came up with this solution, but I'm wondering if there are better ways to it.
List<Integer> numbers = new ArrayList<>();
//... in the meantime numbers is an array that contain 1000 elements;
numbers.remove(0);
myFunction(numbers)
You can use subList(firstElement, lastElement); method.
Here please check javadoc.
This question already has answers here:
How do I declare and initialize an array in Java?
(31 answers)
Closed 5 years ago.
I am trying to declare and instantiate an array named 'canines' that had 25 elements and will hold 'dog' objects...
Is this the best way to do this or is there another formate that would be more correct?
canines[25] = Dog
Dog[] canines = new Dog[25];
Have a look at some of the many online java resources
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Java Remove Duplicates from an Array?
String={3333,4444,5555,5555,1111}
Using Delimiter i have put the String values in an array[]..
Now, How can i remove the same entries in an Array???
Use Set instead, Or use temporarily Set and get the unique result back to array
See
What interface in Java can I use to store unique objects?
This question already has answers here:
Converting a TreeSet to ArrayList?
(3 answers)
Closed 6 years ago.
how can I convert this to a List of the same object type?
TreeSet<FieldBean> Fields = new TreeSet<FieldBean>();
Thanks
One of the constructors of ArrayList takes a collection as an argument and fills the list with the items contained in that collection:
List<FieldBean> list = new ArrayList<FieldBean> (fields);