arraylist

ArrayList and the problem with adding items

Hi, I please for your help. I apologize for my English, it is still learning. I do one application in GUI in Java. I have one problem. In this application I have an ArrayList that I want to meet with data. User clicks on the button and data from JTextfield shall be placed in Arraylist. When they do so, it is inserted only into the ...

When to use ArrayList over array[] in c#?

I often use an ArrayList instead of a 'normal' array[]. I feel as if I am cheating (or being lazy) when I use an ArrayList, when is it okay to use an ArrayList over an array? ...

C# - Array that can be resized fast

I'm looking for a kind of array data-type that can easily have items added, without a performance hit. System.Array - Redim Preserve copies entire RAM from old to new, as slow as amount of existing elements System.Collections.ArrayList - good enough? System.Collections.IList - good enough? ...

Using a long as ArrayList index in java

I am writing this java program to find all the prime numbers up to num using the Sieve of Eratosthenes, but when I try to compile, it says I can't use a long var as an array index, and it expects an int var in its place. But I'll be working with large numbers, so I can't use int. What can I do? import java.util.*; import java.lang.*; p...

C#, a String's Split() method

C#, a String's Split() method, how can I put the resulting string[] into an ArrayList or Stack? ...

Breadth-First search in Java

Hi I am having to run a breadth-first search in Java for an assignment. I have a 5x5 grid of tiles (24 in total - 1 tile is left 'blank'). The point of the search is to rearrange the tiles by moving the 'blank' up, down, left or right to eventually rearrange the tiles into the correct order. To do this search, I have created an Arrayli...

How to count occurrence of an element in a List

I have an ArrayList a collection class of java as follows. ArrayList<String>animals = new ArrayList<String>(); animals.add("bat"); animals.add("owl"); animals.add("bat"); animals.add("bat"); As you can see the animals ArrayList consists of 3 bat elements and one owl element. I was wondering if there is any API in collection framework ...

Move one arraylist data to another arraylist in C#

How to move one Arraylist data to another arraylist. I have tried for many option but the output is in the form of array not arraylist ...

Most efficient way to see if an ArrayList contains an object in Java

I have an ArrayList of objects in Java. The objects have four fields, two of which I'd use to consider the object equal to another. I'm looking for the most efficient way, given those two fields, to see if the array contains that object. The wrench is that these classes are generated based on XSD objects, so I can't modify the classes...

Java: Detect duplicates in ArrayList?

How could I go about detecting (returning true/false) whether an ArrayList contains more than one of the same element in Java? Many thanks, Terry Edit Forgot to mention that I am not looking to compare "Blocks" with each other but their integer values. Each "block" has an int and this is what makes them different. I find the int of a p...

java.util.ArrayList<T>

This is the implementation of java.util.Arrays.asList: () public static <T> List<T> asList(T... a) { return new ArrayList<T>(a); } How can that compile? I can't find a constructor for ArrayList, AbstractList or AbstractCollection that accepts a parameter like T... och T[]. Source code from: java version "1.5.0_16" Java(TM) 2 Run...

Why can't dotnet 1.1 cast down after ArrayList.GetRange?

I'd like to create an array from range of values within an ArrayList but am getting the error "At least one element in the source array could not be cast down to the destination array type". Why should the following fail, and what would you do instead? int[] ints = new int[] { 1, 2, 3 }; ArrayList list = ArrayList.Adapter(ints); int[]...

Need help in storing dynamic value using arraylist

Hello all, Somebody please help me how to store the value dynamically using arraylist.Every time i want to add patient details. Here is my code layer wise: PatientDataLayer: public class PatientData { public string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); public int AddPatien...

Reverse iteration through ArrayList gives IndexOutOfBoundsException

When I reverse iterate over an ArrayList I am getting a IndexOutOfBoundsException. I tried doing forward iteration and there is no problem. I expect and know that there are five elements in the list. The code is below: Collection rtns = absRtnMap.values(); List list = new ArrayList(rtns); Collections.sort(list); for(int j=list.size();j...

How to sort a date array in PHP

I have an array in this format: Array ( [0] => Array ( [28th February, 2009] => 'bla' ) [1] => Array ( [19th March, 2009] => 'bla' ) [2] => Array ( [5th April, 2009] => 'bla' ) [3] => Array ( [19th April, 2009] => '...

Best way to convert an ArrayList to a string

I have an ArrayList that I want to output completely as a String. Essentially I want to output it in order using the toString of each element separated by tabs. Is there any fast way to do this? You could loop through it (or remove each element) and concat it to a String but I think this will be very slow. ...

is there a way to treat a c# static array like an ArrayList?

I have code that uses Arrays and, unfortunately, I can't change their types. If I could, I'd use ArrayLists or something simliar to do what I need to do, but I can't. Basically, I'm looking for the best approach to adding and removing objects from a static array. For adding an item to the array on the fly, i have to create a new array...

How can I retrieve a JDBC ResultSet as an ArrayList?

I'm doing a query to retrieve a large amount of IDs (integers). Instead of iterating millions of times through the ResultSet and copying everything one-by-one to an ArrayList, is there some way to simply retrieve everything as an ArrayList? I understand that ResultSet is supposed to be iterated because the underlying implementation may ...

deep copy NSMutableArray in Objective-C ?

Hi All, Is there any built-in function in Objective-C allows me to deep copy a NSMutableArray? I looked around, some people say [aMutableArray copyWithZone:nil] works as deep copy. But I tried it seems no. Right now I am manually doing the copy one by one (a 9*9 array): //deep copy a 9*9 mutable array to a passed-in reference array ...

How to get the last value of Arraylist

Hi, How can I get the last value of arrayList (e.g. I dont know the last index of the ArrayList)? Thanks. ...