arraylist

Arrays: Counting, Comparing and Increase

Woohoo, I've come to arrays now, thank god. Now, I've got 2 arrays! int colorvalues[][] = {{34,255,255,56},{127,204,11,34},{123,98,127,34},{34,34,127,17}}; Imagine it as a 4x4 pixel picture Now, I want to create a histogram, the distribution of colorvalues from 0 to 255. For example here I've 2*255, 2*127, 5*34 and so on. So I've ...

C#: Do I have to make ArrayList synchronized if multiple threads only read it

I'm using static ArrayList in a class to store information about non-updatable database fields. I'm planing to initialize it in constructor once (init method call guarded by lock in constructor). After that multiple threads check if arraylist Contains a field. Do I have to control this read access in any way? For example by calling Array...

For-Each and Pointers in Java

Ok, so I'm tyring to iterate through an ArrayList and remove a specefic element. However, I am having some trouble using the For-Each like structure. When I run the following code: ArrayList<String> arr = new ArrayList<String>(); //... fill with some values (doesn't really matter) for(String t : arr) { t = " some other value "; //hop...

Multi Level ArrayList extraction

I have an ArrayList that contains Strings and also contains other ArrayLists which may contain Strings or even more ArrayLists. Is there a simple way to extract all the Strings from this multilevel ArrayList? I'm assuming some recursion is invloved but I haven't been able to get it to work. ...

java issues with arraylist

Hey, I'm a bit new to java, so please bear with me. I have a class that contains 2 arraylists which i'm trying to store objects into, one for each object type. in my main class, i'm insert the objects like so: for (int i =0; i < 3; i++) { Cat cat = new Cat("meow",i); Dog dog = new Dog("woof",i); objList.addCat(cat); obj...

Load from Properties.Settings to ArrayList?

Here is the settings file that is leftover from saving. (Saving the properties works correctly.) <setting name="AlarmList" serializeAs="Xml"> <value> <ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <anyType xsi:type="ArrayOfAnyType"> <...

What's an efficient algorithm to make one list equal to another one?

Let's say I have a list A that needs to look exactly like list B. All the objects that B has but A does not have need to be added to A. And all the objects that A has but not B, need to be removed from A. The reason why I need this is because I have an ArrayList of Players that I'm saving to a file. Every time I update an attribute of a...

Bind a multi-dimensional ArrayList to a Gridview

I have a DataGrid of seats available, each with a checkbox to be able to reserve the seat. In the button click event, if the CheckBox is clicked, I am adding the contents of the row to an ArrayList, then adding the ArrayList to a session before redirecting to the confirmation page: protected void Reserve_Click(object sender, EventArgs e...

Calling equals on an ArrayList After Serialization

I am hitting a strange problem in relation to equals on an object transported over RMI. This has been wrecking my head for a few days now and I was wondering if anyone can help shed some light on the Problem. I have a Garage Class (that is also a JPA entity in case its relevant) that I push to a java process called X over RMI (So this o...

Can't find a public symbol variable on one instance of a class (Java)

I am writing a program to calculate the shortest path between two nodes. In my program I have one custom class called NodeList, which contains an ArrayList of strings (representing nodes) along with a distance. I am using Dijkstra's algorithm which involves opening up the shortest edge from each node. So, I use this loop to tabulate the ...

Using SubSonic, how to add a field to a pre-defined class?

I've got a SubSonic DAL - works great. Two classes: TblReceipt and TblReceiptLineItems. I can create a parallel class of TblReceipt, but seems like a waste, so here's what I need to do: Have a Class TblReceipt with one additional member, "ReceiptLineItems" - which is simply an ArrayList. This array list will be populated with TblRec...

traditional for loop vs Iterator in Java

Is there any performance testing results available in comparing traditional for loop vs Iterator while traversing a ArrayList,HashMap and other collections? Or simply why should I use Iterator over for loop or vice versa? ...

Java ArrayList not allowing me to add from outside constructor

public class Start { public Register theReg = new Register(); public static Start go = new Start(); public static void main(String[] args) { Register theReg = new Register(); go.regUsers(); if(theReg.logIn("jsmith","password")) { System.out.println("You're logged in as " + ...

problem in adding two arraylist

Hi, I have two arrayList ArrayList ar1 = new ArrayList(); ArrayList ar2 = new ArrayList(); ar1 is having values { A,B,C,D} and ar2 is having values {1,2,3,4} I want to add these two array list such that output should be A 1 B 2 C 3 D 4 I have used ar1.addrange(ar2); and the output is like this A B C D 1 2 3 4 Any suggestions how t...

handling servlet output in ajax

hi, i am new to java, my problem is i am sending a request to servlet from a jsp page ajax function the servlet process the data and returns a arraylist my question is how to handle the arraylist inside ajax and display it as a table in same jsp page. the code is function ajaxFunction ( ) { // var url= codeid.options[codeid.select...

Add two arraylists in a datatable

I have two arraylists. One contains filenames and the other contains failurecount. These values are from database tables in the code behind. Now I want to add these two arraylists to one datatable. Is there a way to do this? ...

How to add object to an array

My question is about how I add an object to an array, in my case I have an array class with 4 columns and I cant get my program to add an object to the array. I have tried with: DatabaseTable dt = new DatabaseTable(); dt.add("something", "something", "something", "something"); but my program wont run.. Anyone how knows how to do it?...

List<? super B> lsb = new ArrayList<A>(); Logical error in java?

We have: class A{} class B extends A{} class C extends B{} class D extends C{} we can define Lists like: List<? super B> lsb1 = new ArrayList<Object>(); //List<? super B> lsb2 = new ArrayList<Integer>();//Integer, we expect this List<? super B> lsb3 = new ArrayList<A>(); List<? super B> lsb4 = new ArrayList<B>(); //List<? super B...

Java: ArrayList of String Arrays...

I would like to do something like this: private ArrayList<String[]> addresses = new ArrayList<String[3]>(); ...this does not seem to work. Whats the easiest way of storing multiple addresses with 3 fields per address in an array without creating a separate class for it? ...

How to convert nested List into multidimensional array?

In Java I want to convert a nested List which contains at the deepest level a uniform type into an multidimensional array of that type. For example, ArrayList<ArrayList<ArrayList<ArrayList<String>>>> into String[][][][]. I've tried several things and I only can obtain an array of objects like Object[][][][]. For 'simple lists' it seems ...