arraylist

Create an arraylist of struct in C#

Hi there, I have a struct struct myStruct { Dictionary<string, int> a; Dictionary<string, string> b; ...... } I want to create a arraylist of that struct ArrayList l = new ArrayList(); myStruct s; s.a.Add("id",1); s.b.Add("name","Tim"); l.Add(s); However, I got the error "Object reference not set to an instance of an...

How to compare two Arraylist values in java?

Hi I have Two Arraylist RunningProcessList AllProcessList its contains following values are RunningProcessList: Receiver.jar AllProcessList: Receiver.jar Sender.jar Timeout.jar TimeourServer.jar AllProcessList arraylist contains the all java processes , RunningProcessList arraylist contains currently running...

Is this a good way to get the difference of two arraylists?

I have two arraylists, and I would like to have a new arraylist with only the uncommon items. Is this the "best" or at least decent way to do it? Public Function diffLists(ByRef first, ByRef second As Collection) As ArrayList Dim retval As New ArrayList() For Each element In first If Not second.Contains(element) Then ...

Sorting ArrayList of String[]

I have an arraylist of String[]: ArrayList< String [] > mystuff = new ArrayList < String [] > (); I want to sort them in largest-array-size ascending order. Example: mystuff = {["this", "is", "item", "one"], ["this", "is", "item", "two"], ["item"], ["item", "three"]} Should become: mystuff = {["item"], ["item", "thr...

Creating a ListView layout from an ArrayList

What I want to do in one of my tabs in my application is have a ListView of contacts. Though, in that example, the ListView is made from an array of Strings. Is there a way that I can create one of those using the values from an ArrayList? Thanks! ...

Java : convert List of Bytes to array of bytes

Hi All, Trying to solve what should be a simple problem. Got a list of Bytes, want to convert it at the end of a function to an array of bytes. final List<Byte> pdu = new ArrayList<Byte>(); .... return pdu.toArray(new byte[pdu.size()]);; compiler doesn't like syntax on my toArray. How to fix this? ...

Construct an ArrayList of strings in Java as simple as one can in Javascript

In JavaScript I can build an Array of string values like: var stuff = new Array('foo','bar','baz','boz','gaz','goz'); or even easier var stuff = 'foo,bar,baz,boz,gaz,goz'.split(','); In Java it seems overly verbose and complex... is there an easier way than this? ArrayList<String> stuff = new ArrayList<String>(); stuff.add("foo");...

How to carry out ArrayList implementation so as to store person details

Hi, I need to implement an ArrayList which can hold like person records. I can only do this so far: CODE import java.util.*; class ArrayListDemo { public static void main(String args[]) { ArrayList al = new ArrayList(); System.out.println("Initial size of al: " + al.size()); al.add("C"); al.add("A")...

How do you get a float[] out of an ArrayList in Java

I have gotten a float array stuck inside of a ArrayList. the arraylist contains a Boolean and the afore mentioned float array. my courrent code to get it out (which doesn't work) is (float)((Float)((Number)(DXY.get(0)); I would prefer to not have to change the things inside, but if absolutely necessary I could pass the Boolean as a 1...

Java: ArrayList returns Object instead of desired type.

Hello everyone. I'm having a problem that I have encountered before, but I still don't know why it happens. This is the code: package Program; import java.util.ArrayList; import java.util.Iterator; /** * This class will hold the full collection of the user. * * @author Harm De Weirdt */ public class ShowManager { /** * ...

Java ArrayLists into JList

OK so I'm doing a small part of my inventory. I got MOST of it down. I'm trying to add string items to an ArrayList then add that to a JList. However, I'm getting this error when I compile: C:\Users\Dan\Documents\DanJavaGen\inventory.java:30: cannot find symbol symbol : constructor JList(java.util.ArrayList<java.lang.String>) location:...

Java cannot find symbol in List

OK so I switched from JList to List because 1.) It doesn't overlap my drawn images 2.) It can have focus disabled yet track what's selected Anyway, here's the error I get when I try to compile: C:\Users\Dan\Documents\DanJavaGen\inventory.java:30: cannot find symbol symbol : constructor List(java.lang.Object[]) location: class java.aw...

Java: Should I always replace Arrays for ArrayLists?

Well, it seems to me ArrayLists make it easier to expand the code later on both because they can grow and because they make using Generics easier. However, for multidimensional arrays, I find the readability of the code is better with standard arrays. Anyway, are there some guidelines on when to use one or the other? For example, I'm ab...

Java NullPointerException

I tried printStackTrace and I have coverted everything to static (I think)... however, lines 17 and line 38 are the problem... because of this error: You picked up: Pickaxe java.lang.NullPointerException at item.addInv(item.java:38) at item.main(item.java:17) Description: Can be used to mine with. Press any key to contin...

Element goes missing during iteration of Arraylist

Can somebody explain to me whats wrong with the below piece of code ? public static void main(String[] args) { List<String> l = new ArrayList<String>(); l.add("1"); l.add("2"); l.add("3"); l.add("4"); for (int i = 0; i < l.size(); i++) { if(l.get(i).equals("1")) l.remove(l.get(i)); else System.out.println(l.get...

Question about using ArrayList in Java ?

I really do not know if the title is appropriate or not. I have 2 options: OPTION 1: Class A { ArrayList<B> BList = new ArrayList<B>(); public B[] getBList() { return (B[])BList.toArray(); } } Class Facade { public B[] getAllB(){ A a = new A(); return a.getBList(); } } OPTION 2: Class A { Arr...

Compare two arrays or arraylists, find similar and different values

Hi all, I have two arrays (or arraylists if it is easier) of strings. I need to compare these, find which only exist in the first array, which exist in both, and which only exist in the second array. These arrays are different lengths, and may be in different orders. If necessary, I suppose I could sort them... I know I could hack th...

Deep Copy [] and ArrayList Java

Hello, I want to make a Deep Copy of some Object[] and ArrayList How can i do that (without looping , and calling clone) There aren't standard utils for doing this? Thanks João ...

SQL Reading from a DB problem using a DataReader

I have a table of Users (tblUsers) which contains details of University staff. I am trying to populate a text box with the names of lecturers associated with a selected module. I am getting all UserIDs associated with a particular module, testing if the User is a lecturer, if so then I add the ID to an ArrayList. I then iterate throu...

Array List Problem

How do I check for null in a array list and remove them? It keeps giving me a error of "ArgumentOutOfRange was handled" or if I change the SMTPException to just Exception it says "Index out of range". Looking at the debugger and taking a look specifically at mails.Count it gives me Count = 4. I originally gave it 3 emails to check. The l...