arraylist

how to remove a string from arraylist of strings, ANDROID

心已入冬 提交于 2019-12-23 15:11:49
问题 I created an arraylist of strings List<String> textArray = new ArrayList<String>(); and then I added the strings(which I am getting from edittext) to textArray as follows String text = editText1.getText().toString(); textArray.add(text); Now I created a button and need to remove the string from the array when the button is clicked.But i dont know what to do. I know for arrays of bitmaps we clear a bitmap from array using recycle but Please suggest me how to remove or clear the string from

C# 读取CSV文件 通用

血红的双手。 提交于 2019-12-23 13:32:53
//读CSV文件类,读取指定的CSV文件,可以导出DataTable public class CsvStreamReader { private ArrayList rowAL; //行链表,CSV文件的每一行就是一个链 private string fileName; //文件名 private Encoding encoding; //编码 public CsvStreamReader() { this.rowAL = new ArrayList(); this.fileName = ""; this.encoding = Encoding.Default; } /// <summary> /// /// </summary> /// <param name="fileName">文件名,包括文件路径</param> public CsvStreamReader(string fileName) { this.rowAL = new ArrayList(); this.fileName = fileName; this.encoding = Encoding.Default; LoadCsvFile(); } /// <summary> /// /// </summary> /// <param name="fileName">文件名,包括文件路径</param> ///

Java Programming Error: java.util.ConcurrentModificationException

假装没事ソ 提交于 2019-12-23 13:09:14
问题 I'm writing a program as part of tutorial for a beginner Java student. I have the following method and whenever I run it, it gives me the following exception: java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at Warehouse.receive(Warehouse.java:48) at MainClass.main(MainClass.java:13) Here's the method itself, within the class Warehouse: public void receive(MusicMedia

How to override the ToString method of ArrayList of object?

帅比萌擦擦* 提交于 2019-12-23 12:24:11
问题 class Person { public String firstname; public String lastname; } Person p1 = new Person("Jim","Green"); Person p2 = new Person("Tony","White"); ArrayList<Person> people = new ArrayList<Person>(); people.add(p1); people.add(p2); System.out.println(people.toString()); I'd like the output to be [Jim,Tony] , what is the simplest way to override the ToString method if such a method exists at all? 回答1: You actually need to override toString() in your Person class, which will return the firstname,

Store ArrayList<CustomClass> into SharedPreferences

醉酒当歌 提交于 2019-12-23 11:46:00
问题 I have an ArrayList of custom class Task public class Task { String name,desc; Date date; Context context; public Task(String name, String desc, Date date, Context context) { this.name = name; this.desc = desc; this.date = date; this.context = context; } } I want to save it in SharedPreferences.. I read that can be done by converting it to Set.. But I don't know how to do this.. Is there a way to do this? Or any other way to store data rather than SharedPreferences? Thanks :) EDIT: String s =

c# : how to read from specific index in List<person>

£可爱£侵袭症+ 提交于 2019-12-23 09:56:26
问题 I have a class of persons and list collection as list contains all the values of person class such as : List ilist has 2 values [0]={firstname,lastname} . [1]={firstname2,lastname2} now when i am iterating into the list i am able to print the list but i want to change the value of some parts of my list e.g in index 1 if i want to change the value of firstname2 to firstname3 i am not able to do it . Can anyone tell me how to print the list and then on that index changing any value of the index

c# : how to read from specific index in List<person>

泄露秘密 提交于 2019-12-23 09:56:06
问题 I have a class of persons and list collection as list contains all the values of person class such as : List ilist has 2 values [0]={firstname,lastname} . [1]={firstname2,lastname2} now when i am iterating into the list i am able to print the list but i want to change the value of some parts of my list e.g in index 1 if i want to change the value of firstname2 to firstname3 i am not able to do it . Can anyone tell me how to print the list and then on that index changing any value of the index

第十一章:持有对象

纵饮孤独 提交于 2019-12-23 09:55:38
Collection   List     ArrayList               indexOf, contains, remove, removeAll都会用到equals方法       subList所产生的列表幕后就是初始列表       retainAll方法所产生的行为依赖于equals方法       注:看源码ArrayList是通过数组(Object[] elementData)存储数据,有一个size属性(int size)表示集合元素个数,有两个常量int DEFAULT_CAPACITY=10和Object[] EMPTY_ELEMENTDATA = {} 当初始化时elementData=EMPTY_ELEMENTDATA,即空数组,父类AbstractList有modCount属性(int modCount = 0)表示修改次数。     迭代器       迭代器是一个对象,它的工作是遍历并选择序列中的对象,而客户端程序员不必知道或关心该序列底层的结构。Java的Iterator只能单向移动,这个Iterator只能用来:       1)使用方法iterator()要求容器返回一个Iterator。Iterator将准备好返回序列的第一个元素。       2)使用next()获得序列中的下一个元素。       3)使用hasNext(

java迭代器

谁说我不能喝 提交于 2019-12-23 09:54:53
1. I terator 迭代器是一个对象,它的工作是遍历并选择序列中的对象。客户端程序员不关心序列底层的结构。此外,迭代器通常被称为“轻量级”对象:创建它的代价小。因此,经常可以见到对迭代器有些奇怪的限制。 Java 的Iterator 就是迭代器受限制的例子,只能单向移动,它只能用来: a)使用方法 iterator()要求容器返回一个 Iterator。第一次调用Iterator 的next()方法时,它返回序列的第一个元素。 b)使用next()获得序列中的下一个元素。 c)使用hasNext()检查序列中是否还有元素。 d)使用remove()将上一次返回的元素从迭代器中移除。 public class JavaIterator { public static void main(String[] args) { List<Integer> list = Arrays.asList(16, 17, 18, 19, 20); List<Integer> arrayList = new ArrayList<Integer>(list); /*在使用Arrays.asList()后调用add,remove这些method时 出现java.lang.UnsupportedOperationException异常。 这是由于Arrays.asList() 返回java.util

【Java】Iterator迭代器总结

让人想犯罪 __ 提交于 2019-12-23 09:54:20
迭代器是一个对象,它的工作时遍历并选择序列中的对象,而客户端程序员不必知道或关心该序列底层的结构,此外,迭代器通常被称为轻量级对象:创建它的代价小。因此,经常可以见到对迭代器有些奇怪的限制,例如Java的Iterator只能单向移动,这个Iterator只能用来: (1)使用方法iterator()要求容器返回一个Iterator。Iterator将准备好返回序列的第一个元素。 (2)使用next()获得序列中下一个元素。 (3)使用hashnNext()检查序列中是否还有元素。 (4)使用remove()将迭代器新近返回的元素删除。 List<Pet> pets=Pets.arrayList(12); Iterator<Pet> it=pets.iterator(); while(it.hashNext()){ Pet p=it.next(); System.out.print(p); }  有了Iterator就不必为容器中元素的数量操心了,那是hashNext()和next()关心的事情了。  如果只是向前遍历List,并不打算修改List对象本身,那么那可以看到foreach语法会显得更加简洁。 foreach(Pet p: pets){ System.out.print(p); } Iterator还可以移除由next()产生的最后一个元素,这意味着在调用remove(