arraylist

Java Arraylist - Copy one to another without duplicates

I have an ArrayList: Arraylist<Person> list1 = new ArrayList<Person>(); list1.add(new Person("John", 0)); list1.add(new Person("Kane", 0)); list1.add(new Person("Jen", 0)); And another ArrayList: Arraylist<Person> list2 = new ArrayList<Person>(); list2.add(new Person("John", 2)); list2.add(new Person("Kane", 4)); I want the resulti...

Capacity of ArrayList

How to find the capacity of the ArrayList? ...

Problems loading a DataGridView with a two dimensional arrayList

Hello, I am writing an app where I am loading two DataGridViews from a DB. I have successfully done this using a dataAdapter.Fill(DataSet), but the problem I had was that the data coming from the DB has 10s of thousands of records. It is very slow (too slow, about 7 mins) the first time it is ran. The next time it runs the time is mo...

C#, DataTable to ArrayList?

hello, I have a datatable with few rows each row has few columns I want to create an arraylist that countain all row as a string so each array item look like this {1;qwqww;qweqweqwe;qweqweqw;qwe} the items in the string will be separated with ; and it is a .NET 2 solution Thanks ...

Why is my ArrayList.remove(id) call not working?

I have an ArrayList, which includes a number of items I want to remove. I have the ids of the items to remove stored in another list. Figured the following code should work trivially, but for some reason, the remove() calls are returning a false value: ArrayList<Integer> toRemove = new ArrayList<Integer>(); ArrayList<JCheckBox> al...

What is the best way to save the contents of an ArrayList?

I want to save an ArrayList so that it is persistent. The contents can change. What is the best way of approaching this in android? ...

Initializing ArrayList with a new operator in Java?

What is the best practice to initialize an ArrayList in Java? If I initialize a ArrayList using new operator then, the ArrayList will by default have memory allocated for the 10 buckets (say the object) by default. Which is a performance hit. I don't know, might be I am wrong, but it seems to me that I must create a ArrayList by mentio...

Problem serializing and deserializing ArrayList

Anytime I try to serialize a file I get the error: FileNotFound. Not sure why. Here is my FileHelper code: package org.stocktwits.helper; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import jav...

ArrayList and Multithreading in Java

Under what circumstances would an unsynchronized collection, say an ArrayList, cause a problem? I can't think of any, can someone please give me an example where an ArrayList causes a problem and a Vector solves it? I wrote a program that have 2 threads both modifying an arraylist that has one element. One thread puts "bbb" into the a...

Adding items to data source doesn't appear in ListView

I am adding items to my data source and would like it to appear in my ListView. For some reason nothing is appearing: Adapter: private class STCompanyAdapter extends ArrayAdapter<STCompany> { private ArrayList<STCompany> items; public STCompanyAdapter(Context context, int textViewResourceId, ArrayList<...

Insert element to ArrayList with ascending order and no duplicate elements.

I have a homework assignment where I need to insert or add new elemment into ArrayList<Interger> with follow condition: Element must ascending order. No duplicate elements in ArrayList<Integer> insert method run in O(n) times. Here is my insert method for check duplicate element before add new element. public void insert(int x){...

PHP : Problem with Arrays

Hi, I'm a php newbie, and I'm creating a Facebook application for my flash game. In the main page of the application, I want to print the current user friends sorted by score. I get first user friends using my application with this API function: <?php $friends = $facebook->api_client->friends_getAppUsers();?> $friends is an Array wit...

VB.net Memory efficient function needed

Hi All, I'm getting out of memory exceptions from the following function when RowCollection is 50000+ and thus i need to make it more memory efficient. The function is simply needs to construct a comma separated string of the row indexes stored in RowCollection. Can anyone spot any obvious memory hungry operations in the following? N....

Why 10 in the beginning of an ArrayList after Sort()

As the question says i have this problem. I know why it is in the beginning, because it is a 1 and a 0, so therefore its before 9 even after sorting. But, can it be in the right order with the lists sort() method? ...

Can multiple classes serialize the same object in Java?

I am serializing an ArrayList in 2 classes: private void serializeQuotes(){ FileOutputStream fos; try { fos = openFileOutput(Constants.FILENAME, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(quotesCopy); oos.close(); }...

Am I creating my custom ArrayAdapter correctly?

My ListView populates correctly, but for some reason adding and removing is quirky and does not work properly! Am I doing something wrong? Set things up in OnCreate() listView = (ListView) findViewById(R.id.ListView); registerForContextMenu(listView); deserializeQuotes(); if(quotes == null || quotes.size() =...

How to add item to arraylist whit bottonclick?

Something is wrong whit my code. in application when I "add item", it doesnt show anything, and if aim clicking somewhere around the android application, then "item" sometimes comes. Can somebody help me? package com.example.proov; import java.util.ArrayList; import com.example.proov.R; import android.app.Activity; import android.os....

Am I serializing/deserializing correctly?

For some reason when I deserialize my quotes ArrayList, I don't get the right object back. I want to make sure that whenever I read/write my object, it will always be the same object. Serialization code: private void serializeQuotes(){ FileOutputStream fos; try { fos = openFileOutput(Constants.FILENAME, Cont...

ArrayList capacity increment equation

In the JDK 1.7 into the ArrayList.java the method ensureCapacity increments the array capacity using the following expression: int newCapacity = oldCapacity + (oldCapacity >> 1) so it seems that the new capacity will be almost the 50% more than the old. However in many books is said that the capacity is doubled... so the books aren't up...

Java ArrayList of Arrays?

I want to create a mutli dimensional array without a fixed size. I need to be able to add items of String[2] to it. I have tried looking at: private ArrayList<String[]> action = new ArrayList<String[2]>(); but that doesn't work. does anyone have any other ideas? ...