arraylist

ArrayList contains case sensitivity

你说的曾经没有我的故事 提交于 2019-12-17 05:01:10
问题 I am currently using the contains method belonging to the ArrayList class for making a search. Is there a way to make this search case insensitive in java? I found that in C# it is possible to use OrdinalIgnoreCase. Is there a java equivalent, or another way to do this? Thanks. 回答1: You can use this exactly like you'd use any other ArrayList. You can pass this List out to other code, and external code won't have to understand any string wrapper classes. public class CustomStringList3 extends

ArrayList contains case sensitivity

帅比萌擦擦* 提交于 2019-12-17 05:00:04
问题 I am currently using the contains method belonging to the ArrayList class for making a search. Is there a way to make this search case insensitive in java? I found that in C# it is possible to use OrdinalIgnoreCase. Is there a java equivalent, or another way to do this? Thanks. 回答1: You can use this exactly like you'd use any other ArrayList. You can pass this List out to other code, and external code won't have to understand any string wrapper classes. public class CustomStringList3 extends

Empty an ArrayList or just create a new one and let the old one be garbage collected? [duplicate]

爷,独闯天下 提交于 2019-12-17 04:59:26
问题 This question already has answers here : Better practice to re-instantiate a List or invoke clear() (4 answers) Closed 5 years ago . What are the advantages and disadvantages of emptying a collection (in my case its an ArrayList) vs creating a new one (and letting the garbage collector clear the old one). Specifically, I have an ArrayList<Rectangle> called list . When a certain condition occurs, I need to empty list and refill it with other contents. Should I call list.clear() or just make a

How to create an 2D ArrayList in java? [duplicate]

北城余情 提交于 2019-12-17 04:53:35
问题 This question already has answers here : How do I declare a 2D String arraylist? (6 answers) Closed 6 years ago . I want to create a 2D array that each cell is an ArrayList ! I consider this defintions, but I can not add anything to them are these defintions true?! ArrayList<ArrayList<String>> table = new ArrayList<ArrayList<String>>(); or ArrayList[][] table = new ArrayList[10][10]; //table.add?????? Please help me 回答1: I want to create a 2D array that each cell is an ArrayList! If you want

Java中Vector和ArrayList的区别

跟風遠走 提交于 2019-12-17 04:48:52
首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList、Vector和LinkedList。List用于存放多个元素,能够维护元素的次序,并且允许元素的重复。3个具体实现类的相关区别如下: ArrayList是最常用的List实现类,内部是通过数组实现的,它允许对元素进行快速随机访问。数组的缺点是每个元素之间不能有间隔,当数组大小不满足时需要增加存储能力,就要讲已经有数组的数据复制到新的存储空间中。当从ArrayList的中间位置插入或者删除元素时,需要对数组进行复制、移动、代价比较高。因此,它适合随机查找和遍历,不适合插入和删除。 Vector与ArrayList一样,也是通过数组实现的,不同的是它支持线程的同步,即某一时刻只有一个线程能够写Vector,避免多线程同时写而引起的不一致性,但实现同步需要很高的花费,因此,访问它比访问ArrayList慢。 LinkedList是用链表结构存储数据的,很适合数据的动态插入和删除,随机访问和遍历速度比较慢。另外,他还提供了List接口中没有定义的方法,专门用于操作表头和表尾元素,可以当作堆栈、队列和双向队列使用。 vector是线程(Thread)同步(Synchronized)的,所以它也是线程安全的,而Arraylist是线程异步(ASynchronized)的,是不安全的

How to zip two Java Lists

ぃ、小莉子 提交于 2019-12-17 04:33:10
问题 I have 2 Lists: List<String> subjectArr = Arrays.asList<String>("aa", "bb", "cc"); List<Long> numArr = Arrays.asList<Long>(2L, 6L, 4L); How do I create new List and zip two Lists into it? List<?> subjectNumArr = zip(subjectArr, numArr); // subjectNumArr == [{'aa',2},{'bb',6},{'cc',4}] 回答1: Here's Java-8 solution using the Pair class (like in @ZhekaKozlov answer): public static <A, B> List<Pair<A, B>> zipJava8(List<A> as, List<B> bs) { return IntStream.range(0, Math.min(as.size(), bs.size()))

C# Permutation of an array of arraylists?

[亡魂溺海] 提交于 2019-12-17 04:31:30
问题 I have an ArrayList[] myList and I am trying to create a list of all the permutations of the values in the arrays. EXAMPLE: (all values are strings) myList[0] = { "1", "5", "3", "9" }; myList[1] = { "2", "3" }; myList[2] = { "93" }; The count of myList can be varied so its length is not known beforehand. I would like to be able to generate a list of all the permutations similar to the following (but with some additional formatting). 1 2 93 1 3 93 5 2 93 5 3 93 3 2 93 3 3 93 9 2 93 9 3 93 Does

C# Permutation of an array of arraylists?

这一生的挚爱 提交于 2019-12-17 04:31:13
问题 I have an ArrayList[] myList and I am trying to create a list of all the permutations of the values in the arrays. EXAMPLE: (all values are strings) myList[0] = { "1", "5", "3", "9" }; myList[1] = { "2", "3" }; myList[2] = { "93" }; The count of myList can be varied so its length is not known beforehand. I would like to be able to generate a list of all the permutations similar to the following (but with some additional formatting). 1 2 93 1 3 93 5 2 93 5 3 93 3 2 93 3 3 93 9 2 93 9 3 93 Does

Time complexity for java ArrayList

ε祈祈猫儿з 提交于 2019-12-17 04:28:59
问题 Is ArrayList an array or a list in java? what is the time complexity for the get operation, is it O(n) or O(1) ? 回答1: An ArrayList in Java is a List that is backed by an array . The get(index) method is a constant time, O(1) , operation. The code straight out of the Java library for ArrayList.get(index) : public E get(int index) { RangeCheck(index); return (E) elementData[index]; } Basically, it just returns a value straight out of the backing array. ( RangeCheck(index) ) is also constant

Time complexity for java ArrayList

荒凉一梦 提交于 2019-12-17 04:28:36
问题 Is ArrayList an array or a list in java? what is the time complexity for the get operation, is it O(n) or O(1) ? 回答1: An ArrayList in Java is a List that is backed by an array . The get(index) method is a constant time, O(1) , operation. The code straight out of the Java library for ArrayList.get(index) : public E get(int index) { RangeCheck(index); return (E) elementData[index]; } Basically, it just returns a value straight out of the backing array. ( RangeCheck(index) ) is also constant