arraylist

Why there is only one data in the List<String>?

感情迁移 提交于 2020-01-25 12:30:49
问题 I used cursor for database selecting and want to put all the data inside a List, then return to the mainactivity. But after debugging, I found that there is only the first data inside the return value. public List<String> select1 (String ReservedState, String mycity, String mystreet, String mypostcode){ ReservedState="Free"; SQLiteDatabase Database1=dbHelper1.getWritableDatabase(); String[] columns={DbHelper1.KEY_ID1,DbHelper1.KEY_RESERVEDSTATE, DbHelper1.KEY_GEOGRAPHICALLOCATION,DbHelper1

面试-集合

二次信任 提交于 2020-01-25 08:39:35
一、请说明List、Map、Set三个接口存取元素时,各有什么特点? 答:①List以特定索引来存取元素,可以有重复元素。 ②Set不能存放重复元素(用对象的equals()方法来区分元素是否重复)。 ③Map保存键值对映射,映射关系可以是一对一或者是多对一。 Set和Map容器都有基于哈希存储和排序树的两种实现版本,基于哈希存储的版本理论存取时间复杂度为O(1),而基于排序树版本的实现在插入或删除元素时会按照元素或元素的键构成排序树从而达到排序和去重的效果。 二、阐述ArrayList、Vector、LinkedLIst的存储性能和特性。 答:ArrayList和Vector都是使用数组方式存储数据,此数组元素数大于实际存储的数据以便增加和插入元素,它们都允许直接按序号索引元素,但是插入元素要涉及数组元素移动等内存操作,所以索引数据快而插入数据慢。Vector中的方法由于添加了synchronized修饰,因此Vector是线程安全的容器,但性能上比较ArrayList差,因为已经是java中的遗留容器。 LinkedList使用的是双向链表实现存储,按序号索引数据需要进行前向或后向遍历,但是插入数据时只需要记录本项的前后项即可,所以插入速度较快。 Vector属于遗留容器,已经不推荐使用,但是由于ArrayList和LinkedListed都是非线程安全的

Struct not being populated

北城以北 提交于 2020-01-25 07:30:08
问题 I have a struct called Item and wish to populate its variables. struct Item { var title: String var others: [String] } Programs is an array of all the Item ’s created. var Programs = [Item]() I created a struct Item by the following: var entered = Item(title: hello1, others: ["hello2"]) The problem is that when I go to print the list of Items , the programs array is empty print(Programs) 回答1: You need to append it print("Before :",programs) let entered = Item(title: hello1, others: ["hello2"]

android json to listview

两盒软妹~` 提交于 2020-01-25 07:25:21
问题 I working with android and JSON. I came so far, but I can's set the ID in the arraylist.The error will be in "json_data.getInt("ID")" Can sombody help me public void klussenlijst() { ArrayList<String> results = new ArrayList<String>(); JSONObject json_data; mysql client = new mysql("http://www.****************/klussen.php?actie=klussen"); try { client.Execute(RequestMethod.POST); } catch (Exception e) { e.printStackTrace(); } String response = client.getResponse(); try{; JSONArray jArray =

Java 删除String[] 数组元素

回眸只為那壹抹淺笑 提交于 2020-01-25 05:57:37
文章目录 一. java中删除String[]数组中的指定元素 二. Java 删除String[] 数组中的多个元素 一. java中删除String[]数组中的指定元素 问题:删除String[] 数组中指定的元素 解决办法: 我们需要先转换成List ,然后移除该元素,会报错 String items [ ] = { "1" , "2" , "3" , "4" , "5" } ; List < String > list1 = Arrays . asList ( items ) ; //将数组转换为list /* 发现直接: list1.remove("2");会报错: Exception in thread "main" java.lang.UnsupportedOperationException */ 通过网上查找报错原因如下: 调用Arrays.asList()生产的List的add、remove方法时报异常,这是由Arrays.asList() 返回的是Arrays的内部类ArrayList, 而不是java.util.ArrayList。 Arrays的内部类ArrayList和java.util.ArrayList都是继承AbstractList,remove、add等方法AbstractList中是默认throw

Android Switching between Viewpager produces Android crash

ぃ、小莉子 提交于 2020-01-25 05:55:52
问题 I have five fragments in an View pager. One of them is a BarcodeFragment BarcodeFragment and I am getting a very weird android crash when I swipe between ViewPager fragments quickly. The crash Im getting is on the android side. This is the log. java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) at java.util.ArrayList.set(ArrayList.java:481) at android.support.v4.app.FragmentManagerImpl.makeInactive

Java: check if arraylist is part of fibonacci sequence

不羁的心 提交于 2020-01-25 04:01:05
问题 My assignment for school is to implement a method that checks if a given ArrayList is part of the Fibonacci sequence. The array must not be empty and must be bigger than 3. I understood that I have to check if one number of the array and the next one are part of the Fibonacci sequence, however I have a lot of trouble with it since you're supposed to accept the array if it's any part of the sequence and not just from the start. e.g.: 0 1 1 2 3 5 will be accepted as well as 2 3 5 8 13 21 . This

ArrayList,LinkedList

拥有回忆 提交于 2020-01-25 03:24:51
ArrayList基本介绍 1、Arraylist是一个能够进行扩容的动态数组,但是和数组又不太一样,继承了AbstractList,实现了List、RandomAccess, Cloneable, java.io.Serializable。 public class ArrayList < E > extends AbstractList < E > implements List < E > , RandomAccess , Cloneable , java . io . Serializable > boolean add ( E e ) 尾插e > void add ( int index , E e ) 在index位置插入e > boolean addAll ( Collection < ? extends E > c ) 尾插c中的元素 > E remove ( int index ) 删除index位置的元素 > boolean remove ( Object o ) 删除第一个遇到的o > E get ( int index ) 获取index位置的元素 > E set ( int index , E e ) 将index位置设置为e > void clear ( ) 清空 > boolean contains ( Object o ) 判断o是否在线性表中 >

How can I catch an exception in an enhanced for loop and restart the process for this loop?

断了今生、忘了曾经 提交于 2020-01-25 02:28:15
问题 I have started working with enhanced for loops due to it's best practices and habilities to work with ArrayLists . My code basically gets an ArrayList that contains links to songs and parses this list downloading the songs. One of the exceptions thrown is the TimeoutException, whitch normally happens when the server is overloaded or there's an instability with the internet connection. To clarify: try { for(Track track : album.getTracks()) { songdown.downloadTrack(track, directorio,

Populating Listview By Passing Multiple ArrayLists Through Custom BaseAdapter

喜欢而已 提交于 2020-01-25 01:47:10
问题 Solve the mystery of populating a listview through a custom adapter, which is being passed multiple arraylists as defined below. MAIN ACTIVITY: we declare the arraylists: private static ArrayList<Integer> img_challengeicon_values; static { img_challengeicon_values = new ArrayList<Integer>(); img_challengeicon_values.add(R.drawable.actionbar_hello); img_challengeicon_values.add(R.drawable.actionbar_world); } private static ArrayList<Integer> img_challengerpic_values; static { img_challengerpic