arraylist

Have I found a bug in java.util.ArrayList.containsAll?

℡╲_俬逩灬. 提交于 2019-12-25 07:58:51
问题 In Java I've two lists: List<Satellite> sats = new ArrayList<Satellite>(); List<Satellite> sats2 = new ArrayList<Satellite>(); Satellite sat1 = new Satellite(); Satellite sat2 = new Satellite(); sats.add(sat1); sats2.add(sat1); sats2.add(sat2); When I do the following containsAll method on the first list: sats.containsAll(sats2); //Returns TRUE! It returns true. But the first List (sats) only contains 1 item and the second list contains 2. Therefor it's not even possible that the first list

Grouping of words from a text file to Arraylist on the basis of length

大城市里の小女人 提交于 2019-12-25 07:58:35
问题 public class JavaApplication13 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here BufferedReader br; String strLine; ArrayList<String> arr =new ArrayList<>(); HashMap<Integer,ArrayList<String>> hm = new HashMap<>(); try { br = new BufferedReader( new FileReader("words.txt")); while( (strLine = br.readLine()) != null){ arr.add(strLine); } } catch (FileNotFoundException e) { System.err.println("Unable to find the file:

Efficient way of finding all strings of an Arraylist, which contains a substring

风格不统一 提交于 2019-12-25 07:47:54
问题 I have a string, say a="1.1" and an arraylist, say list , which has the strings: "1.1.1.1", "1.1.2.4","1.2,1.3","1.5.1.1" Now, I want to get the strings from this arraylist, which contains the string a="1.1" at the beginning, that means a is a substring of those string and need to match from beginning. So, for this case, answer will be 1.1.1.1 and 1.1.2.4 but not 1.5.1.1 as here 1.1 is not at the beginning. I know, how to achieve this but I think my solution is not efficient enough and for

Arraylist populating Listview in separate class not working

大憨熊 提交于 2019-12-25 07:23:53
问题 I'm trying to add an item to arraylist/adapter on a Button click in my class MyMaxes.java: Date currentDate = new Date(); ArrayAdapter<Record> records = new ArrayAdapter<Record>(getApplicationContext(), R.layout.custom_record); records.add(new Record(currentDate ,maxSquat, maxBench, maxDead, maxTotal)); records.notifyDataSetChanged(); And in my other class, MyProgress.java, I'm trying to assign that adapter to the ListView: ListView listViewRec = (ListView) findViewById(R.id.listViewRecord);

toString an arraylist containing object

混江龙づ霸主 提交于 2019-12-25 07:12:48
问题 I have an array list of type car. I have an overriding toString method which prints my car in the desired format. I'm using the arraylist.get(index) method to print the cars. I only have one for now it works, but I want it do print for all of the cars in the array list. This is my code: public class Garage { private static int carsCapacity = 30; ArrayList<Cars> myGarage; public Garage() { Scanner scanAmountOfCars = new Scanner(System.in); System.out.println("Please limit the number of car the

android base adapter does not adapter all rows

只谈情不闲聊 提交于 2019-12-25 06:55:20
问题 I have two datetimes 12/01/2014 and 12/10/2014.i changed datetime format and i also checked different between there two datetime and i also incremented days between there datetimes.for more information 1 dec,2 dec,3 dec .....10 dec this is a my source public class MoviesRolls extends Fragment { public final static String TAG = MoviesRolls.class.getSimpleName(); private ListView holllistview; private HollAdapters adapter; public static ArrayList<CinemaInfoModel> cinemaInfoArray; public static

Writing arraylist to textfile

放肆的年华 提交于 2019-12-25 06:48:20
问题 I have an arraylist of class Room which is held in class Hostel , i would like to write this arraylist to a text file. What is the most efficient method of doing so? Hostel Class public class Hostel { private ArrayList < Room > rooms; } Room Class abstract class Room { public Room(int newRoomNo, boolean newRoomEnSuite, int newRoomNights, String newRoomBooker) { roomNo = newRoomNo; roomEnSuite = newRoomEnSuite; roomBooking = "Booked"; roomNights = newRoomNights; roomBooker = newRoomBooker; } }

Passing Array<Object> from one activity to another [duplicate]

拜拜、爱过 提交于 2019-12-25 06:36:24
问题 This question already has answers here : How to pass an object from one activity to another on Android (31 answers) Closed last year . I have the following two classes. public class People{ private int mobile_number; private String email_id, name; private Testimony[] testimony; public People(String name, int mobile_number, String email_id, Testimony ... testimony) { this.name = name; this.mobile_number = mobile_number; this.email_id = email_id; this.testimony = testimony; } public Testimony[]

Java_集合面试题

亡梦爱人 提交于 2019-12-25 06:07:07
Java_集合面试题 0.链表,队列和栈的区别? 链表是一种存储结构,指得是存储时候除了要存储数据元素之外,还要用数据元素一起的另外空间存储数据元素的关系。 队列和栈都是线性表,属于逻辑结构范畴,都是访问点受到限制,并且限制在线性表端点的线性表。 栈被限定为在线性表中的同一个(唯一一个的)端点插入删除 队列被限定为在线性表的一端插入,另外一个端点删除 栈和队列也可以用链表来实现,分别称为链栈和链队列 1. ArrayList ArrayList是基于数组实现的,最大长度不会超过数组的长度2147483647(最大值是int的最大值是,2的31次方减去1 ).如果业务中可能存在超过这个长度的数据,使用LinkedArrayList 3.HashMap Java中的HashMap是以键值对(key-value)的形式存储元素的。HashMap需要一个hash函数,它使用hashCode()和equals()方法来向集合/从集合添加和检索元素。当调用put()方法的时候,HashMap会计算key的hash值,然后把键值对存储在集合中合适的索引上。如果key已经存在了,value会被更新成新值。 HashMap的一些重要的特性是它的容量(capacity),负载因子(load factor)和扩容极限(threshold resizing)。 4.HashMap和HashTable的区别

How to display “no result found” using arraylist in struts2

穿精又带淫゛_ 提交于 2019-12-25 06:04:06
问题 Here I am firing some query ..and it displays record but what i want is if there is no record then it should display "no match/result found" . I am using ArrayList in Struts2 . So can i be able to achieve it ? Please if anyone can make changes or suggest something that would be very helpful. I have searched solution for this but wasn't able to get relevant solution. Below I am posting my Action class and jsp page on which i want to display results. Thanks in advance. :) BookSearchAction.java