arraylist

Java: substitute for ArrayList cos primitive types not allowed in ArrayList?

Primitive types are not allowed in ArrayList, source. Partial solution: you can wrap prim.types such as int to Integer to form an extra class but a side effect. I want to index data, is there some substitute for ArrayList that allows primitive types? ...

Java: initialization problem, cannot print "assigned" values from arrayList

$ javac ArrayListTest.java $ java ArrayListTest $ cat ArrayListTest.java import java.io.*; import java.util.*; public class ArrayListTest{ public static void main(String[] args) { try { String hello ="oeoaseu oeu hsoae sthoaust hoaeut hoasntu"; ArrayList<String> appendMe = null; for(S...

How to shuffle pairs

How to shuffle the elements in the pairs? The program below, generate all possible pairs and later shuffle the pairs. e.g. possible pairs before shuffle is ab,ac,ae,af..etc shuffled to ac,ae,af,ab...etc How to make it not only shuffled in pairs but within the elements in the pair itself? e.g. instead of ab, ac, how can I make ba, ac ? ...

Having trouble binding a ksoap object to an ArrayList in Android

I'm working on an app that calls a web service, then the webservice returns an array list. My problem is I am having trouble getting the data into the ArrayList and then displaying in a ListView. Any ideas what I am doing wrong? I know for a fact the web service returns an ArrayList. Everything seems to be working fine, just no data in t...

hashmap in java

i have a hashmap where every key has many values(stored in a arraylist). How to display the arraylist i.e the values for a particular key in a hashmap in java?? ...

Compare new Integer Objects in ArrayList Question

I am storing Integer objects representing an index of objects I want to track. Later in my code I want to check to see if a particular object's index corresponds to one of those Integers I stored earlier. I am doing this by creating an ArrayList and creating a new Integer from the index of a for loop: ArrayList<Integer> courseselectItem...

How does a Java Arraylist contains() method evaluate objects?

Say i create one object and add it to my ArrayList. If I then create another object with exactly the same constructor input, will the contain() method evaluate the two objects to be the same? Assume the constructor doesn't do anything funny with the input, and the variables stored in both objects are identical. ArrayList<Thing> basket =...

Java - java.util.List problem

I have a java.util.ArrayList<Item> and an Item object. Now, I want to obtain the number of times the Item is stored in the arraylist. I know that I can do arrayList.contains() check but it returns true, irrespective of whether it contains one or more Items. Q1. How can I find the number of time the Item is stored in the list? ======...

Arraylist as repeater datasource (how to access from .aspx)

I have an arraylist: Dim downloadsarray As New ArrayList downloadsarray.Add(iconlink) downloadsarray.Add(imgpath) downloadsarray.Add(filesize) downloadsarray.Add(description) Which is the datasource of my repeater: DownloadsRepeater.DataSource = downloadsarray DownloadsRepeater.DataBind() P...

Given an array of integers [x0 x1 x2], how do you calculate all possible permutations from [0 0 0] to [x0 x1 x2]?

I am writing a program that takes in an ArrayList and I need to calculate all possible permutations starting with a list of zeroes, up to the value in the corresponding input list. Does anyone know how to iteratively calculate these values? For example, given [ 1 2 ] as input, it should find and store the following lists: [0 0], [1 0]...

How do I use xStream to output Java Objects with List properties?

Hello, I am trying to output some Java objects as JSON, they have List properties which I want to be formatted as { "People" : [ { "Name" : "Bob" } , { "Name" : "Jim" } ] } However, I cannot figure out how to do this with XStream. It always outputs as { "Person" : { "Name" : "Bob" }, "Person" : { "Name" : "Bob" } Is there a way to fi...

Java: How ArrayList manages memory

In my Data Structures class we have studies the Java ArrayList class, and how it grows the underlying array when a user adds more elements. That is understood. However, I cannot figure out how exactly this class frees up memory when lots of elements are removed from the list. Looking at the source, there are three methods that remove ele...

Adding instances of a class to an Arraylist in java

I have 10 instances of the class movie which I wish to add to an Arraylist named Catalogue1 in a class containing a main method I write the following ArrayList catalogue1= new ArrayList () //the class movie is defined in another class Movie movie1= new Movie () Movie movie2= new Movie () Catalogue.Add (1, movie1) What ...

how to use an array list ?

I need to know if i store my data in an ArrayList and I need to get the value that I've stored in it For example : if I have an array list like this ArrayList A = new ArrayList(); A = {"Soad", "mahran"}; and I want to get each String element, how can I do it ? I've tried to do it like this package arraylist; import ...

C# Saving an arraylist to a file?

I have a simple program where I would like to save an arraylist to a file, so that when the program is restarted, it loads from the file to the arraylist in memory. Is this possible in C#? Or do I need to itterate over the arraylist countaining my custom classes and in someway print them out? Any tips on a correct way to do this? ...

Arraylist uses Array?

Does an ArrayList internally use an Array? Is this an empty array if we use the default constructor (new ArrayList())? Thanks. ...

Java ArrayList Middle

How to find the middle of an ArrayList ? ...

Arraylist can't compare objects after they are loaded from disk

To make it easy, lets say I have an arraylist allBooks containing class "books" and an arraylist someBooks containing some but not all of the "books". Using contains() method worked fine when I wanted to see if a book from one arraylist was also contained in another. The problem was that this isn't working anymore when I save both of t...

Concurrent threads adding to ArrayList at same time - what happens?

We have multiple threads calling add(obj) on an ArrayList. My theory is that when add is called concurrently by two threads, that only one of the two objects being added is really added to the ArrayList. Is this plausable? If so, how do you get around this? Use a synchronized collection like Vector? ...

Java Memory Overhead

Hello, I would like to ask about Memory Overhead in java, I have a large ArrayList (61,770 items), and trying to calculate the amount of memory taken by each item (counting the object and its ArrayList entry), by profiling the app i get that after all the data is loaded, the heap takes ~ 25Mb. when the ArrayList has only 2 items the heap...