Skip to content
Advertisement

Tag: arraylist

Check if ArrayList Contains same array order ignored

I’ve initialized an ArrayList holding int arrays as such: ArrayList<int[]> holder = new ArrayList<int[]>(); If I add an int[] like this: int[] first = {1, 2, 3}; holder.add(first); If I do this check, I want the function to return true, but it returns false right now int[] second = {2, 1, 3}; if(holder.contains(second)) return true; else return false Answer You

Decrease the number of calls

I have arraylist of filenames (java) and I want to delete these files using rm but it is time consuming can I do batching using xargs or something else which can help to delete files faster. Answer Don’t use rm. Use Java. As others have pointed out, spawning a process is much slower than doing it in your program. Also,

In an array of arraylists, get the largest arraylist

I have an array with multiple arraylists of different sizes. I want to find the index of the largest arraylist in the array. I tried this: disc being the name of the array of arraylists. ArrayList I believe doesn’t implement the Comparable interface so I can’t do it like this. Is there a way to make a custom comparable for

How to cast an object of an ArrayList of objects (of type superclass) to an object of type subclass

If I have a superclass, let’s call it Car, with the constructor parameters String name, String color, double wheelSize, and a subclass of this, let’s call it Truck, with the constructor parameters String name, String color, double wheelSize, and double truckBedArea, and in the subclass (Truck), I have a method called modifyCar with the paramaters Car car, String newName, String

Easy sort list 2D by column

I’m quiet new in Java data manipulation so I need some help if someone have a some good tips. Actually, I want just to find a easy way to sort a 2D list. I create a list like this: And then I want to have a result sorted by the second element like: I tried something like Arrays.sort(A.toArray(), (int[]a, int[]b)

How can I convert arraylist to arraylist

My goal is to find on which specific index is String from ArrayList and add them to new ArrayList, So if house is [0] than i want to return new ArrayList with integer. At the begging I have ArrayList like this Input : And I want to get new ArrayList like this Output: Answer You can do it just by

Remove numbers from a list that begins with a specif digit

For example, i have this list How i remove only the numbers that begins with “6” Answer There are several ways how you can approach this task: using an Iterator; by utilizing so-called traditional for loop; with a help of Stream IPA; using method Collection.removeIf(). Note that attempt to address this problem using enhanced for loop (sometimes called “for-each” loop)

How to iterate through ArrayList values of HashMap?

A question from a total newbie. Sorry. I have this customersOrders HashMap that takes String as keys and ArrayList<Double> as values. I need to find the total sum of orders for each customer and the maximum total sum in order to find the biggest customer. How do I manage to do that using just nested For loops and HashMap methods?

Advertisement