arraylist

Shifting in arrayList

冷暖自知 提交于 2021-02-08 15:37:52
问题 The method public static <T> ArrayList<T> rotate(ArrayList<T> aL, int shift) accepts an Arraylist of String (at least in this example) and a shift which indicated how much the arraylist should shift. If I have, let's say an arayList of [ A, B, C, D, E, F, G] and the shift is 2 , so the method returns [ F, G, A, B, C, D, E] or another example, [ A, B, C, D, E, F, G] and shift is 4 , then the method returns [ D, E, F, G, A, B, C] I did the method completely wrong and have no clue how to

How to store java.util.ArrayList in Postgresql using Spring

空扰寡人 提交于 2021-02-08 13:47:17
问题 I am trying to do a batch-insert of a collection of beans. One of the properties of the bean is an ArrayList. The batch update fails with the exception: Can't infer the SQL type to use for an instance of java.util.ArrayList. Use setObject() with an explicit Types value to specify the type to use. I don't know which Postgresql data type to use for the ArrayList to be compatible. Is there a way I can do the batch update of the beans without changing the data type of its properties? The Bean:

ArrayList with multiple arguments (User input)

元气小坏坏 提交于 2021-02-08 10:25:54
问题 I am trying to create a App base on user input with ArrayList. But there is some problem that I need to understand first. PS: I want to try with normal value first before going into user input. And this is just a rough sketch up to make me understand how to use multiple arguments in a arraylist. This is the Student package test; import java.text.SimpleDateFormat; import java.util.Date; public class Student { private String name; private Date DOB; private String[] friend; private String school

Index was out of range after deleting multiple rows from the datagridview? C#

自古美人都是妖i 提交于 2021-02-08 10:13:08
问题 I use an ArrayList for my binary search. The datagridview's rows is added to the ArryList. When I deleting a single row from the datagridview, it works almost perfectly. The problem is when I delete many rows from the datagridview from the top or the bottom and middle, it gives me an error. How can I refresh or update the ArrayList after I deleted a row from the ArrayList (datagridview)? The error: 'Index was out of range. Must be non-negative and less than the size of the collection.

How to convert list of Image file paths into list of bitmaps quickly?

房东的猫 提交于 2021-02-07 20:19:53
问题 ArrayList<String> imageFileList = new ArrayList<>(); ArrayList<RecentImagesModel> fileInfo = new ArrayList<>(); File targetDirector = new File(/storage/emulated/0/DCIM/Camera/); if (targetDirector.listFiles() != null) { File[] files = targetDirector.listFiles(); int i = files.length - 1; while (imageFileList.size() < 10) { File file = files[i]; if (file.getAbsoluteFile().toString().trim().endsWith(".jpg")) { imageFileList.add(file.getAbsolutePath()); } else if (file.getAbsoluteFile().toString

difference on list.add() AND list.add(new ArrayList<>())? [duplicate]

风格不统一 提交于 2021-02-07 18:07:11
问题 This question already has answers here : Why does my ArrayList contain N copies of the last item added to the list? (5 answers) Closed 3 years ago . the following code: List<List<Integer>> res = new ArrayList<>(); List<Integer> row = new ArrayList<>(); for (int i = 1; i <= 3; i++) { row.add(i); res.add(row); } res: [ [1,2,3],[1,2,3] ,[1,2,3]] wrote in this way: for (int i = 1; i <= 3; i++) { row.add(i); res.add(new ArrayList<>(row)); } res: [ [1],[1,2] ,[1,2,3]] 回答1: In the first case, you've

How to create a list with specific size of elements

半世苍凉 提交于 2021-02-07 13:27:38
问题 Say, I want to create a list quickly which contains 1000 elements. What is the best way to accomplish this? 回答1: You can use Collections.nCopies. Note however that the list returned is immutable. In fact, the docs says " it the newly allocated data object is tiny (it contains a single reference to the data object) ". If you need a mutable list, you would do something like List<String> hellos = new ArrayList<String>(Collections.nCopies(1000, "Hello")); If you want 1000 distinct objects, you

Remove an object from an ArrayList given only one attribute

末鹿安然 提交于 2021-02-07 12:51:36
问题 I have an ArrayList of Items and I want to be able remove one Item from the list by entering only one Item attribute, for example its number (int ItemNumber). I also wanna do the same when I check Item quantities. These are my equals() & contains() methods, do I need to make any changes here? public boolean contains(T anEntry) { boolean found = false; for (int index = 0; !found && (index < numberOfEntries); index++) { if (anEntry.equals(list[index])) found = true; }//end for return found; } /

How to find the difference of two timestamps in java?

邮差的信 提交于 2021-02-07 05:54:47
问题 I have an ArrayList including several number of time-stamps and the aim is finding the difference of the first and the last elements of the ArrayList . String a = ArrayList.get(0); String b = ArrayList.get(ArrayList.size()-1); long diff = b.getTime() - a.getTime(); I also converted the types to int but still it gives me an error The method getTime is undefined for the type String . Additional info : I have a class A which includes String timeStamp = new SimpleDateFormat("ss S").format(new

Difference between ArrayList and LinkedList in Java - the whys for performance

这一生的挚爱 提交于 2021-02-07 03:09:35
问题 I thought I understood the difference between ArrayList and LinkedList theoretically pretty well. However, its the first time, I put it to a little test, and the tests came out, well different to my expectations. Expectations : Arraylist will be slower than LinkedList when inserting at the beginning, since it has to "shift" the elements, for linkedlist, its just updating 2 references. Reality : came out to be same on most iterations. For a select few iterations, it was slower. Arraylist will