arraylist

Overwriting pre-defined array

荒凉一梦 提交于 2019-12-25 06:01:22
问题 I have an array named columnsArray[] it is pre-defined to contain 6 Strings. When i run my method columns() it should overwrite the columnsArray[] with a new array of Strings that the user selects by checking boxes. The way i have tried to implement this adds each box checked to an arrayList and then convert the arrayList to array[]. However when the code is run, columnsArray is not overwritten. Here is my code so far: public class EditView { private JFrame frame; JCheckBox appNo, name,

Collections.sort not sorting ArrayList as expected [beanshell, Java, JMeter]

徘徊边缘 提交于 2019-12-25 05:48:07
问题 I have some Java code which I am using in Beanshell processor (JMeter). This java code is simple and valid. It should simply sort the numeric arraylist but it is giving strange behavior: // Input data is like below: student_id_RegEx_1=13 student_id_RegEx_11=4 student_id_RegEx_12=23 student_id_RegEx_13=24 // CREATE ARRAY LIST AND STORE ELEMENTS IN IT ArrayList strList = new ArrayList(); for (int i=0;i<25; i++){ strList.add(vars.get("student_id_RegEx_" + String.valueOf(i+1))); } // Print the

Java - calling methods of an object that is in ArrayList

我是研究僧i 提交于 2019-12-25 05:32:19
问题 I have a class Kostka , that has its own width (w), height (h), x and y positions for drawing it later on a JPanel using this method void maluj(Graphics g) { g.drawRect(x, y, w, h); } Now I need to make more of them and add them in ArrayList .. then call the maluj(g) method for each of the Kostka object stored in the ArrayList So far I've managed to make a method that stores the Kostka objects in ArrayList, but I dont know how to call their methods class MyPanel extends JPanel { ArrayList kos

Passing ArrayList Object between activities using parcelable

此生再无相见时 提交于 2019-12-25 05:25:12
问题 Ill first start this off saying i have seen all the other posts that deal with this and have tried all of them. Im trying to do the same thing asked in the other posts, which is to pass the values of a ArrayList from one activity to another using Intent. I feel I have implemented my class(es) correctly. The main class (Route_Class) i am using is below. ``` public class Route_Class implements Parcelable { private double latitude = 0; private double longitude = 0; private double startingLat = 0

Android delete from list is wrong

吃可爱长大的小学妹 提交于 2019-12-25 05:17:19
问题 My current code to retrieve data from webservice is the following: try{ for(int i = 0; i <= list.size() - 1; i++){ SoapObject request = new SoapObject(NAMESPACE + "/", "get_all"); request.addProperty("host", host); request.addProperty("user", user); request.addProperty("pass", pass); request.addProperty("bd", bd); request.addProperty("id", list.get(i)); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request);

Arraylist Sublist IndexOutOfBounds Exception

試著忘記壹切 提交于 2019-12-25 05:13:49
问题 Working on below code to Modify HL7 messages and add some Hex Characters depending on condition i have written. Copying the String from the textbox and converting it to Arraylist so that i can traverse through it to find the names of the HL7 segments. To do so i am getting a sublist out of Arraylist. But when working with below code i am getting IndexOutOf Bounds exception. I know that when searching for Sublist my search is exceeding the size of Arraylist. Just need a tip to check if the

reading ArrayList JTextFields

随声附和 提交于 2019-12-25 04:57:52
问题 My program starts by prompting the user how many text fields they would like to have public class textEvent1 implements ActionListener { //action listener for "how many masses?" public void actionPerformed (ActionEvent e) { n = (int)(Double.parseDouble(massNumField.getText())); next I create a for loop to create labels and textfields (which I have created lists for because I dont know how many there will be). There are a couple of lists but I will give an example of just one. ArrayList masses

java编程的一些注意事项

倾然丶 夕夏残阳落幕 提交于 2019-12-25 04:51:41
下面是参考网络资源和总结一些在java编程中尽可能做到的一些地方 1. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时间,提高加载的效率,但并不是所有地方都适用于单例,简单来说,单例主要适用于以下三个方面 第一,控制资源的使用,通过线程同步来控制资源的并发访问 第二,控制实例的产生,以达到节约资源的目的 第三,控制数据共享,在不建立直接关联的条件下,让多个不相关的进程或线程之间实现通信 2. 尽量避免随意使用静态变量 要知道,当某个对象被定义为stataic变量所引用,那么gc通常是不会回收这个对象所占有的内存,如 public class A {    static B b = new B(); }    此时静态变量b的生命周期与A类同步,如果A类不会卸载,那么b对象会常驻内存,直到程序终止。 3. 尽量避免过多过常的创建 java 对象 尽量避免在经常调用的方法,循环中new对象,由于系统不仅要花费时间来创建对象,而且还要花时间对这些对象进行垃圾回收和处理,在我们可以控制的范围内,最 大限度的重用对象,最好能用基本的数据类型或数组来替代对象。 4. 尽量使用 final 修饰符 带 有final修饰符的类是不可派生的。在Java核心API中,有许多应用final的例子,例如java.lang.String。为String类指

How to get SQLite db values in Arraylist to Listview

旧时模样 提交于 2019-12-25 04:33:41
问题 I need to set adapter values in a listview. In it, I created an ArrayList to get data from SQLite DB and I need to pass it to a listView with 3 columns. Here I mentioned my codes. Where do I need to call my data Stored in local Db? DBHelper.java public ArrayList<SQLPojo.UserDetails> getUserDetails() { ArrayList<SQLPojo.UserDetails> aUserDetailList = new ArrayList<SQLPojo.UserDetails>(); try { String aQuery = "SELECT * FROM " + TABLE_NAME; Cursor aCursor = mySqliteDataBase.rawQuery(aQuery,

Java Merge Sorting Algorithm Error - Not Sorting

痴心易碎 提交于 2019-12-25 04:22:27
问题 I can't figure out why my algorithm for a Merge Sort program using ArrayLists won't work... If guys and gals could help me figure it out that would be amazing!! The format required for printing needs to be tabbed every number and place on a new line every 20 numbers. My program has also been limited to the standard Java packages. Sample input and output can be found here. Here's my code: import java.io.*; import java.util.*; public class MergeSort { public static void main(String[] args)