arraylist

How to read a file from internal storage or external storage and store the file in a arrayList in android

↘锁芯ラ 提交于 2020-07-23 07:49:25
问题 My requirement is the end-user must be able to upload files into the application from internal or external storage and finally display the name of the file in the page. Actual result: Now I've fetched the file name from the storage and displayed the name in my page. Expected Result: The end user must be able to load image or video files from external or internal storage to the application and finally display their name in the page. But don't have any idea about how to load read the file from

Kotlin MutableList initial capacity

前提是你 提交于 2020-07-21 04:11:27
问题 I'm creating a list of values, in a context where it so happens that, though the values are being added one at a time, the eventual number is known in advance. This is in a function that will be called many times, so the faster it runs, the better. In Java, I would use the ArrayList constructor that specifies an initial capacity, because in theory this makes it slightly faster because it avoids resizing. In Kotlin, one normally uses mutableListOf(), but this does not allow an initial capacity

Cast from Optional<> to ArrayList<>

[亡魂溺海] 提交于 2020-07-18 11:40:46
问题 I have the following situation: public ArrayList<A> getMethods(){ return b.c.test(); } So, my problem is that b.c.test() returns a value with Optional<A> as return type. But I need to return an ArrayList<A> . So, I tried to cast it and rewrite it to : public ArrayList<A> getMethods(){ return (ArrayList<A>)b.c.test(); } But Eclipse says that such a cast from Optional<A> to ArrayList<A> is not possible. How can I solve this problem? 回答1: I am presuming your intended semantic is 'if the value is

How To Display Objects in Java JList?

强颜欢笑 提交于 2020-07-16 10:54:01
问题 I'm trying to create a student registration system. In this system, students can see course name, course credit, and the instructor of the course by clicking the "Courses" button.For this purpose i have a Courses class, a database, a frame and a JList courslist. ArrayList<Courses> aq = Database.allCourses(); //allCourses() is a static method in my Database class that returns fields from my Database as an ArrayList<Courses> courselist.setListData(Driver.converToCoursesArray(aq)); //Driver

How to convert an arrayList.toString() into an actual arraylist

China☆狼群 提交于 2020-07-16 02:26:52
问题 In my software, since there is no Array data type in SQLite , I saved my ArrayList as a String . Now I need to use my array and want to convert it back to an ArrayList. How can I do it? Here an example : ArrayList<String> list = new ArrayList<String>(); list.add("name1"); list.add("name2"); list.add("name3"); list.add("name4"); list.add("name5"); list.add("name6"); String newList = list.toString(); System.out.println(newList); Result: [name1, name2, name3, name4, name5, name6] So now how can

How do I pass ArrayList<Object> from one Activity to another Activity

我与影子孤独终老i 提交于 2020-07-10 10:27:28
问题 I want to pass ArrayList of an Object from one Activity to Activity. Here is the sample Code: { ArrayList<object> list=new ArrayList<>(); Object value[]=new Object[m.size()]; int n=0; value[]=new Object[n]; value[n]=data.getName("name"); value[n]=data.getLocation("location"); list.add(value[n]); n++; //Since there are "n" number of object } //here the value a which is ArrayList Object // which I want to pass it from here to another activity. So now how will I pass the object from here to

Array list not getting split properly

孤者浪人 提交于 2020-07-09 12:16:30
问题 The value ALL||test > test's done> test's done again's done||test > test's done> test's done again's done 2 is an array list what i want to do is have a list separated by || so the first element is : ALL second: test > test's done> test's done again's done last: test > test's done> test's done again's done 2 code i wrote: String record1 = record.toString(); String[] parts = record1.split("||"); for (int i = 1; i <= parts.length; i++) { System.out.println(parts[i]); } What i'm getting is each

Slideshow from an ArrayList of images with JavaFX

风流意气都作罢 提交于 2020-07-09 06:58:26
问题 I'm trying to create a slideshow by taking an ArrayList of images and putting them into an ImageView using a for loop. However, in order to "pause" the program so that each image will be visible, I am trying to use Thread.sleep . This unfortunately hasn't had the desired effect. In trying to remedy this, my endless googling leads me to suspect that I should be using the Timeline class, but I have no idea how to implement it. Any help would be much appreciated. My dysfunctional code as it

Select value from arraylist based on its percentage [duplicate]

空扰寡人 提交于 2020-07-07 15:18:19
问题 This question already has answers here : How to pick an item by its probability? (12 answers) Closed 4 years ago . I got an arraylist of objects. Each objects got 2 values, content and weight . content is just a simple string while weight decides the percentage of how often the string should be used. If I have 2 objects in the array: Object 1: content: hello weight: 20 Object 2: content: hey weight: 80 First objects content should be used 20% of times while the second objects content should

Select value from arraylist based on its percentage [duplicate]

喜你入骨 提交于 2020-07-07 15:14:19
问题 This question already has answers here : How to pick an item by its probability? (12 answers) Closed 4 years ago . I got an arraylist of objects. Each objects got 2 values, content and weight . content is just a simple string while weight decides the percentage of how often the string should be used. If I have 2 objects in the array: Object 1: content: hello weight: 20 Object 2: content: hey weight: 80 First objects content should be used 20% of times while the second objects content should