arraylist

Making ArrayList to JTable

[亡魂溺海] 提交于 2019-12-30 07:05:07
问题 I have an ArrayList<Map<String, Object>> Object, I need to display the content of this array in a JTable. The Map - Key is the column name and Object is the data, how can I put it up? Baiscally the Map contains multiple-rows from a table and all the rows are added to the array list, now I need to display them in a Swing application in the form of a table and perform sorting and filtering on them. 回答1: For datas embed your list in a TableModel. A DefaultTableModel is best. For columns, embed

List vs List iterator

一曲冷凌霜 提交于 2019-12-30 06:50:27
问题 I have one list: List<Object> myList = new ArrayList<Object>(); To get from this list there are two methods: 1. for(Object obj : myList ) { // some code } 2. Iterator<Object> objIt = myList.iterator(); while(obj.hasNext()) { Object obj = (Object)objIt.next(); // some code } My question is which one is memory efficient and iterates fast? 回答1: They do the same thing - the enhanced for loop is just syntactic sugar for the longhand version (for iterables; for arrays it's slightly different).

Java remove duplicate objects in ArrayList [duplicate]

独自空忆成欢 提交于 2019-12-30 06:19:12
问题 This question already has answers here : How do I remove repeated elements from ArrayList? (38 answers) Closed 6 years ago . I have a very lengthy ArrayList comprised of objects some of them however, are undoubtedly duplicates. What is the best way of finding and removing these duplicates. Note: I have written a boolean-returning compareObjects() method. 回答1: Example List<Item> result = new ArrayList<Item>(); Set<String> titles = new HashSet<String>(); for( Item item : originalList ) { if(

Convert int[] into ArrayList [duplicate]

℡╲_俬逩灬. 提交于 2019-12-30 06:01:12
问题 This question already has answers here : How to convert int[] into List<Integer> in Java? (18 answers) Closed 6 years ago . What is best way recopying int[] array elements into ArrayList ? I need to do this fast so what would be the fastest way? 回答1: Use Arrays#asList(T... a) to create "a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)" Integer[] intArray = {1, 2, 3, 42}; // cannot use int[] here List<Integer> intList = Arrays.asList

Are List and List<String> the same in Groovy?

好久不见. 提交于 2019-12-30 05:45:19
问题 Question 1 Is it irrelevant whether a List (list of objects) or a List<String> (list of Strings) is used in Groovy? In the code example below, both lists end up being an ArrayList (ArrayList of objects). Would have expected the second list to be an ArrayList<String> (ArrayList of Strings). Does Groovy lose the type information when the class is compiled and infer it when the compiled class is executed? Example 1 List untypedList = ["a", "b", "c"] List<String> typedList = ["a", "b", "c"]

Using and declaring generic List<T>

☆樱花仙子☆ 提交于 2019-12-30 05:45:15
问题 So I'm working in Java and I want to declare a generic List. So what I'm doing so far is List<T> list = new ArrayList<T>(); But now I want to add in an element. How do I do that? What does a generic element look like? I've tried doing something like List.add("x") to see if I can add a string but that doesn't work. (The reason I'm not declaring a List<String> is because I have to pass this List into another function that only takes List<T> as an argument. 回答1: You should either have a generic

List implementations: does LinkedList really perform so poorly vs. ArrayList and TreeList?

为君一笑 提交于 2019-12-30 05:45:11
问题 Taken from the Apache TreeList doc: The following relative performance statistics are indicative of this class: get add insert iterate remove TreeList 3 5 1 2 1 ArrayList 1 1 40 1 40 LinkedList 5800 1 350 2 325 It goes on to say: LinkedList is rarely a good choice of implementation. TreeList is almost always a good replacement for it, although it does use sligtly more memory. My questions are: What is with the ArrayList add , insert , and remove times crushing LinkedList ? Should we expect,

Java - get element position in array

时光怂恿深爱的人放手 提交于 2019-12-30 05:39:05
问题 I'm familiar with the ways I can get an element position in array, especially the ones showed here: Element position in array But my problem is I can't figure out how to convert this code to fit my needs. What I want to check is if a String has a match in an ArrayList and if so, what's the index of the String in the ArrayList. The annoying part is I managed to verify the String is in the ArrayList (see first line of my code) listPackages is the ArrayList current_package is the String I want

How to convert ArrayList into string array(string[]) in c#

蹲街弑〆低调 提交于 2019-12-30 05:37:08
问题 How can I convert ArrayList into string[] in C#? 回答1: string[] myArray = (string[])myarrayList.ToArray(typeof(string)); 回答2: A simple Google or search on MSDN would have done it. Here: ArrayList myAL = new ArrayList(); // Add stuff to the ArrayList. String[] myArr = (String[]) myAL.ToArray( typeof( string ) ); 回答3: use .ToArray(Type) string[] stringArray = (string[])arrayList.ToArray(typeof(string)); 回答4: Try do that with ToArray() method. ArrayList a= new ArrayList(); //your ArrayList object

C# equivalent for java arraylist supporting get, set and remove certain Index

一世执手 提交于 2019-12-30 04:01:05
问题 I am a Java programmer, I have used a Java ArrayList before and now I want to have something like that in C#. Some of options I need are in this Java code: String[] strs = new String[]{"str1" , "str2" , "str3" , "str4"}; ArrayList arrayList = new ArrayList(35); arrayList.add(strs[0]); arrayList.add(strs[1]); arrayList.remove(0); arrayList.set(0, strs[2]); String s = (String) arrayList.get(1); I used C# ArrayList and LinkedList , but they don't have these simple options that I need. Is there