arraylist

C# ArrayList calling on a constructor class

I'm aware that an ArrayList is probably not the way to go with this particular situation, but humor me and help me lose this headache. I have a constructor class like follows: class Peoples { public string LastName; public string FirstName; public Peoples(string lastName, string firstName) { ...

Appending Integer array elements in Java

I have an array, say int a[]={2,0,1,0,1,1,0,2,1,1,1,0,1,0,1}; I need to append each of the 5 neighboring elements and assign them to a new array b with length=(a.length/5); and i want to append the 5 neighboring elements so that I have: int b[]={20101,10211,10101}; I need to do this for various length arrays, in most cases with lengt...

How to use ArrayList to store some data using ICollection

I want to store few strings into an array using ArrayList. How can I store all the strings at once without using Add function every time. Is it somewhat related to interface ICollection in anyway. Can I use ICollection to store my array. If yes How. ArrayList _1019=new ArrayList("TEN","ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN"...

Write a program which works out which is the lowest priced computer in an ArrayList of computer objects.

Hello everybody! I am trying to study some java and cannot get my head around this question! Any help would be really appreciated and would help me in further studies! Thank you so much in advance! Eoin from Dublin, Ireland. ArrayList of Objects Write a program which works out which is the lowest priced computer in an ArrayList of comp...

How to find multiples of the same integer in an arraylist?

Hi My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i'm unsure how to count how many of each of the values exist. The problem is how to find the duplicate values in the arraylist and count how many of that par...

Convert an ArrayList to an object array

Hello, Is there a command in java for conversion of an ArrayList into a object array. I know how to do this copying each object from the arrayList into the object array, but I was wondering if would it be done automatically. I want something like this: ArrayList<TypeA> a; // Let's imagine "a" was filled with TypeA objects TypeA[] ar...

Java ArrayList initialization

I am aware that you can initialize an array during instantiation as follows: String[] names = new String[] {"Ryan", "Julie", "Bob"}; Is there a way to do the same thing with an ArrayList? Or must I add the contents individually with array.add()? Thanks, Jonathan ...

C# multi-dimensional array, ArrayList, or hash table?

hello, I'm trying to figure out how to build a multi-dimensional "array" that is: flexible size use 2 keys 1st key is int (flexible) 2nd key is string (kind of limited) The use will be like: console.writelen(array[0]["firstname"]); console.writelen(array[0]["lastname"]); console.writelen(array[0]["phone"]); console.writelen(array[...

Find all numbers that appear in each of a set of lists

I have several ArrayLists of Integer objects, stored in a HashMap. I want to get a list (ArrayList) of all the numbers (Integer objects) that appear in each list. My thinking so far is: Iterate through each ArrayList and put all the values into a HashSet This will give us a "listing" of all the values in the lists, but only once I...

How to create and display a list in Java?

i have to create a list of ,let's say 50 people, (in Java) and display the list, and i don't really know how to do that. so this is what i have tried to do so far . please correct and complete some of my code . public class Person { String name; String stuff; } public class CreatePerson { public static void ang() { ...

ArrayList without repetition

Hi I'm using arraylist in java and I need to add integers during 10 iterations (integer is got randomly from an array of integers named arrint) without any repetition: for (int i =0; i<10; ++i) array.add(integer); and then add in the same array 20 other integers for the same array of integer(arrint) during 20 iteration without re...

ArrayList of my objects, indexOf problem

Hello! I have problem with Java's ArrayList. I've created an Object, that contains two attributes, x and y. Now I've loaded some object in my ArrayList. Problem is that I don't know how to find index of some object with x atribute I'm searching. Is there any way to do this? ...

convert ArrayList.toString() back to ArrayList in one call

I have a toString() representation of an ArrayList. Copying the toString() value to clipboard, I want to copy it back into my IDE editor, and create the ArrayList instance in one line. In fact, what I'm really doing is this: my ArrayList.toString() has data I need to setup a unit test. I want to copy this ArrayList.toString() into my...

how to read data from file into array? java

I need some help reading data from a txt file into my ArrayList. I know the code is pretty messy, but just try to take a look at it. The first part with the creating and putting the ArrayList into the txt file works perfectly. I just need some help at the end in the "marked" area. Sorry if I still have some words in my native language...

How does Java handle ArrayList refrerences and assignments?

Hey all- I mostly write in C but am using Java for this project. I want to know what Java is doing here under the hood. ArrayList<Integer> prevRow, currRow; currRow = new ArrayList<Integer>(); for(i =0; i < numRows; i++){ prevRow = currRow; currRow.clear(); currRow.addAll(aBunchOfItems); } Is the prevRow = currRow line c...

Using selection sort in java to sort floats

Hey, I need to sort an array list of class house by a float field in a certain range. This is my code for the selection sort: Basically sortPrice copies the stuff in this list into a new one selecting only the values in that range, then it does a selection sort in that array list. The arraylist (x) in sortPrice is unsorted an needs to be...

How do I pass an ArrayList to method that takes a collection as an input

I want to pass some ArrayList<Integer> X into method a(Collection<Integer> someCol) that takes Collection<Integer> as an input. How can I do this? I thought an ArrayList was a Collection and thus I should be able to "just do it" but it seems that Collection is an interface and ArrayList implements this interface. Is there something I ca...

ArrayList in java

ArrayList<String> veri1 = new ArrayList<String>(); String[] veri2 = {"Fatih", "Ferhat", "Furkan"}; How can i add "veri2" to "veri1" like one element ? I mean if i call veri.get(0), it returns veri2.. Regards. ...

date comparison inside a list returned

I have a ArrayList returned from a service which contains date-timestamp as String values (with values: 2010-05-06T23:38:18,2010-05-06T23:32:52,2010-04-28T18:23:06,2010-04-27T20:34:02,2010-04-27T20:37:02) to be more specific, This is part of a parent ArrayList ObjectHistory. This list contains the datestamp and serial number. I need to ...

Is an ArrayList automatically declared static in Java, if it is an instance variable?

I'm trying to do something like this: private class aClass { private ArrayList<String> idProd; aClass(ArrayList<String> prd) { this.idProd=new ArrayList<String>(prd); } public ArrayList<String> getIdProd() { return this.idProd; } } So if I have multiple instances of ArrayLIst<String> (st1 ,st2 ,st3) and I w...