arraylist

set array values in to a text area in java

风格不统一 提交于 2020-01-05 07:52:09
问题 i want to set an array list value in to a text area. this is my code, ArrayList<String> phone_numberArray = db.getNumberSms(); for(int i=0; i<phone_numberArray.size(); i++){ jtext_area.addElement(phone_numberArray.get(i)); } this code getting errors. some one help me please.... 回答1: I assume jtext_area is an instance of JTextArea , I don't see any addElement() in that class, You might be looking for append() 回答2: Try: for(String number : db.getNumberSms()) { jtext_area.append(number); } 来源:

Assigning probability to a random enum object

左心房为你撑大大i 提交于 2020-01-05 07:41:12
问题 So I have an enum here: public enum Party { DEMOCRAT, INDEPENDENT, REPUBLICAN } and I currently have this, one of three classes: public class ElectoralCollege { public static final String FILE = "Electoral201X.txt"; private ArrayList <State> stateVotes; Random rand = new Random(); public ElectoralCollege() throws IOException { stateVotes = new ArrayList<State>(); assignStates(); } public void assignStates() throws IOException { File f = new File(FILE); Scanner fReader = new Scanner(f); while

Combination of getter and list modification in Java

对着背影说爱祢 提交于 2020-01-05 07:25:42
问题 today i dealt with a Java problem that really confused me. I have the following code: List<ObjectXY> someList = obj.getListOfObjectsXY(); // getter returns 2 elements someList.add(new ObjectXY()); obj.getListOfObjectsXY(); // getter now returns 3 elements When i add an element to a list, the getter gets some kind of overwritten. Is this because someList acts like a reference on the result of the getter in this case? Or what else causes this effect? I solved the problem with the following code

Syntax error on ArrayList declaration

眉间皱痕 提交于 2020-01-05 05:22:05
问题 I've got the following code: import java.util.*; public class Group { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); } } Eclipse (3.0.0) complains about the ArrayList declaration: syntax error on token "(", on both tokens "<", and then on token "=". I'm using java 1.5.0_07. What am I doing wrong? Thanks, regards, Miel. 回答1: Set your JDK level to >= 5.0 to enable support for generics. It's at Project -> Properties -> Java Compiler -> Compiler

Extending ArrayList with determined default member type

青春壹個敷衍的年華 提交于 2020-01-05 05:07:39
问题 i am new at java, so i don't know what this technique called, and i may be poor at explain things, but i hpe you understand. Assume i have this two class, Item and it might be extended to ExtendedItem public class Item { } public class ExtendedItem extends Item {} i want to create collection wrapper for it, so i create a class extended from ArrayList... (Scenario 1) public class DataSet extends ArrayList<Item> {} then initialize it DataSet dataset1 = new DataSet(); DataSet<ExtendedItem>

Not able to get the array values from firebase database

£可爱£侵袭症+ 提交于 2020-01-05 04:57:30
问题 I'm trying to check whether the signed in user is an authorized user from the JSON array in Firebase Database. How do I get the value of email field from Firebase. ? This is the model User class: public class User { ArrayList<User> email; public User() {} public ArrayList<User> getEmail() { return email; } public void setEmail(ArrayList<User> email) { this.email = email; } } For getting the email from userslist , I used this logic. usersListDatabaseReference.addValueEventListener(new

Avoiding a possible concurrency issue with a LIST being returned

徘徊边缘 提交于 2020-01-05 04:33:08
问题 Here is the sequence that bother me begging a standard remedy for a concurrency issue Create a list object (lst) Initiate multple threads (Updater Threads) Send that lst to each Updater Threads to update (add) it. Wait for some defined time (t1) to let the Updater threads to proceed with updates. After t1 time expired, return lst to another application (Consumer-App) that isn't in our control. When return it, Updater Threads may be still updating the lst. Consumer-App doesn't know whether the

How to let a method accept two types of data as argument?

浪子不回头ぞ 提交于 2020-01-05 04:26:07
问题 I have a method, accepting a Hashtable (yes I know, it's outdated..) as argument: public static LuaTable HashtableToLuatable(Hashtable t, int depth = 1) This works correctly. Now I'd like to accept an ArrayList as first parameter as well, so you can let 't' have the value of both a Hashtable and an ArrayList. Currently I have copy-pasted the method two times, like this: public static LuaTable ArraylistToLuatable(ArrayList t, int depth = 1) The rest is exactly the same. I think there's a way

学习笔记-java 集合

偶尔善良 提交于 2020-01-05 04:12:48
背景: 看的是《java核心技术 第8版》,覆盖jdk1.6。主要是对集合全局和细节进行全面掌握,较深入的理解集合。本人对java比较熟悉,但是对于细节的理解不深,知识点还不全,这是知识的查缺不漏。 一.集合接口 接口和实现分离 当程序中使用集合时,一旦构建了集合就不需要知道究竟使用的哪种实现,因此,只有构建集合对象时,使用具体的类才有意义。可以使用接口类型存放集合的引用。 2. 集合接口和迭代接口 java迭代器应该认为是位于两个元素中间,当调用next时,迭代器就越过下一个元素。 Iterator接口的remove方法会删除上次调用next方法时返回的元素。重要的是,对next方法和remove方法的调用具有互相依赖性。 为了能够让实现者更容易得实现这个接口,java类库提供了一个类AbstractCollection。 二.具体的集合 1.链表 linkedlist Linkedlist和Arraylist区别:从实现上,al采用的是数组,可以高效地随机访问;而ll采用的是内部了entry,这个类里有对象还有节点的前后指针,因此不能随机访问,只能从头遍历,但是插入,删除简单,不需要移动前后数据。 Linkedlist.add方法将对象添加到链表的尾部;而经常需要在链表的中间插入元素,而接口Iterator中没有add方法,集合类提供了子接口Listiterator

[转]Java中常用的集合—初学者的你不可错过的精编整理

旧街凉风 提交于 2020-01-05 02:29:32
集合一直都是项目中非常常见的,我是一个Android开发者,集合对于我来说,在项目中使用的次数非常之多,因为使用的多,熟能生巧,所以这里呢!就给那些初学者整理一下Java当中常用的集合吧!   因为此篇文章是给初学者看到,所以对于集合的认识,我们就不从内存的角度去分析了,等你Java学到一定的时候,再去学习一下集合的底层实现,这会让成为一名更加牛的Java程序员。   在整理之前呢,我们先聊一聊为什么集合会这么常用?,集合这个概念,我们初次接触是在高中的数学当中,高中的集合具有以下知识点:   1、集合的含义:某些指定的对象集在一起就成为一个集合,其中每一个对象叫元素。   2、集合的中元素的三个特性:   ①.元素的确定性;②.元素的互异性;③.元素的无序性   说明: (1)对于一个给定的集合,集合中的元素是确定的,任何一个对象或者是或者不是这个给定的集合的元素。   (2)任何一个给定的集合中,任何两个元素都是不同的对象,相同的对象归入一个集合时,仅算一个元素。   (3)集合中的元素是平等的,没有先后顺序,因此判定两个集合是否一样,仅需比较它们的元素是否一样,不需考查排列顺序是否一样。   高中的集合理解起来很简单,高中的集合里面放到是一个一个具体的对象,集合当中对象与对象之间是不一样的,而且集合中对象的元素是杂乱无章的,顺序没有什么规律可循,因为高中集合是无序性的