arraylist

java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) Error

回眸只為那壹抹淺笑 提交于 2019-12-24 16:50:50
问题 Can someone help me understand what is wrong with this code? I want to be able to add all contacts associated with the query to a ArrayList. But using just the 'add' command make the loop apparently override it and make the size 1 again. But using the 'add' method with a index causes this error. 'IndexOutOfBoundsError'. pls. do help me. This the error log. 08-14 21:36:29.893 20439-20439/? E/Zygote﹕ MountEmulatedStorage() 08-14 21:36:29.893 20439-20439/? E/Zygote﹕ v2 08-14 21:36:29.943 20439

For-loop which should print out ArrayList attribute and other ArrayList Attribute

天涯浪子 提交于 2019-12-24 16:19:51
问题 I am trying to print out attribute from two different ArrayLists in the same syso. Cant get it to work and killed myself finding out why it doesnt for (int i = 0; i < resultlist.size(); i++) { Athlete matched = null; Result res = resultlist.get(i); for (int x = 0; x < resultlist.size(); x++) { Athlete del = athletes.get(i); if (res.compStartNumber() == del.startNumber()) { matched = del; break; } } System.out.println(matched.surName() + " " + matched.lastName() + " has result: " + res

How to search in an List and my List is look like : List<Object> myList = new ArrayList<Object>() [duplicate]

孤街浪徒 提交于 2019-12-24 16:09:08
问题 This question already has answers here : What is the best way to filter a Java Collection? (27 answers) Closed 3 years ago . I want to search in a List and my List is look like List<Employee> oneEmp= new ArrayList<Employee>(); List<Employee> twoEmp= new ArrayList<Employee>(); oneEmp= [Employee [eid=1001, eName=Sam Smith, eAddress=Bangluru, eSalary=10000000], Employee [eid=0, eName=, eAddress=, eSalary=null], Employee [eid=1003, eName=Amt Lime, eAddress=G Bhagyoday, eSalary=200000], Employee

using the toString method to display information in an arraylist without brackets and commas

北城余情 提交于 2019-12-24 15:37:17
问题 I am using a toString method to display data in an arraylist. How do I write the code so that it displays the information without the [ , , ] around my information see the code below: case 6: System.out.println("Enter an account number to view the transactions of the account"); number=keyboard.nextLong(); found=false; try{ for(int i=0;i<aBank.getAccounts().size();i++){ if(aBank.getAccounts().get(i).getAccountNumber().compareTo(number)==0){ found=true; System.out.println("Account " + number +

How can I store my ArrayList values to MySQL databases?

∥☆過路亽.° 提交于 2019-12-24 15:32:05
问题 I have some problem to store arraylist value to mysql database with php. This is some code I have been created. First, I have some class to store variable its called Constant.java : public class Constant { public static final String FIRST_COLUMN = "First"; public static final String SECOND_COLUMN = "Second"; public static final String THIRD_COLUMN = "Third"; public static final String FOURTH_COLUMN = "Fourth"; } Second, I have been import that class to MainActivity.java like this : import

Powershell's adding Integers when populating arrayList

和自甴很熟 提交于 2019-12-24 14:42:36
问题 I have a function in Powershell which populates a list with dictionaries. Function Process-XML-Audit-File-To-Controls-List($nodelist){ #Keep an array list to track the different controls $control_list = New-Object System.Collections.ArrayList foreach($var in $nodelist) { $lines = [string]($var.InnerText) -split '[\r\n]' $control_dict = @{} foreach($line in $lines){ $line_split = $line.Trim() -split ':',2 if($line_split.Length -eq 2){ $control_dict.Add($line_split[0],$line_split[1]) } }

Java: Index out of bounds

久未见 提交于 2019-12-24 14:33:01
问题 I'm programming in Greenfoot for a school project and I keep getting this error: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.rangeCheck(ArrayList.java:635) at java.util.ArrayList.get(ArrayList.java:411) at Speler.act(Speler.java:60) at greenfoot.core.Simulation.actActor(Simulation.java:583) at greenfoot.core.Simulation.runOneLoop(Simulation.java:541) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java

how to add action to arraylist item in listview and how to get its position?

这一生的挚爱 提交于 2019-12-24 14:32:14
问题 Hi I am working with android.I had created a listview using array list. Now how can I add Action to each list item and also how to get the list position of that item. Please help me, thanks here is my code public class MainActivity extends Activity { private ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView lv=(ListView)findViewById(R.id.listView1); ArrayList<String> list=new

java - check if a substring is present in an arraylist of strings in java

╄→尐↘猪︶ㄣ 提交于 2019-12-24 14:29:43
问题 suppose i've an arraylist (arr1) with the following values: "string1 is present" "string2 is present" "string3 is present" "string4 is present" i wanted to see if the substring 'string2' is present in this arraylist. by looping through the arraylist and using 'get' by index i extracted element at each index and then using 'contains' method for 'Strings' i'm searched for 'string2' and found a match for (int i=0;i<arr1.size(); i++) { String s1=arr1.get(i); if (s1.contains("string2")) { System

Getting only the first name in an array

梦想的初衷 提交于 2019-12-24 14:00:39
问题 I have an array list like this: ArrayList names = new ArrayList<>(); that stores people's first and last names when they are entered in different textbooks. So when prompted to Joe Biden would be element number 1 then Barack Obama would be element number 2 in the array list. My question is that if it is possible to only get their first names like Joe from the array without getting Biden also? 回答1: Yes you could just do names.get(0).split("\\s+")[0] //this would get you "Joe" to get last name