There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham wrote:Generally if you find there's something which uses built-in functions, as opposed to code you write yourself, you'll find the built-in functions work better. For example if you were writing code to sort an array, you would probably write a bubble sort, which is less efficient than the built-in sort function. The people who wrote the built-in functions were aware of all the "Java is slow" propaganda articles out there on the internet and they did spend time making sure they worked well.
You could of course (in this example) spend some (a lot of) time and write a sort which worked faster than the standard sort, because it took advantage of some specific feature of your data. But you wouldn't do that unless you had a good idea of what to do. You don't, in this case, so you wouldn't do that. So stick with the shorter code.
Middle path.
Nawa Man wrote:Have you try LinkedList<int[]>? If I am not mistaken, ArrayList use array as backend and its insert operation performance is not as good as link-list that LinkedList use.
The pairs will need to be order according to various criteria. There will be multiple criteria for each list. I can order the pairs by sorting the 2d array after it has been assembled, presumably I will need one sort for each criteria, or If I use an ArrayList I would order at the time the list is assembled, using <b>list1.add( int, <E> );</b>
Middle path.
William Brogden wrote:Have you considered a custom object:
m[index] = new myObj(i,j) ;
This might simpify your ordering comparators and your list manipulations.
Bill
that it would have a negative impact on performance
Fred Hamilton wrote:Intuition tells me that ...
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|