arrays

How do I remove unwanted values from the begining of an array in Perl?

I am storing values in an array using the push function. The first value in array is being stored at 4 element instead of first element. For instance, after storing values when I print first element $array[1] it prints space/nothing but when I print the fourth element $array[4] it prints the first value. Any suggestions on how to remove ...

How to create an array of string vectors in Java ?

I use the following code try to create an array of string vectors, I hope to have an array of 3 items, each item is a string vector : Vector<String> Result_Vector_Array[]=new Vector<String>[3]; But NB highlighted the line as error(generic array creation), what's wrong ? What's the correct way to do it ? I know there is also Arraylist,...

What is the built-in PHP function for "compressing" or "defragmenting" an array?

I know it'd be trivial to code myself, but in the interest of not having more code to maintain if it's built in to PHP already, is there a built-in function for "compressing" a PHP array? In other words, let's say I create an array thus: $array = array(); $array[2000] = 5; $array[3000] = 7; $array[3500] = 9; What I want is an array w...

How to get a column from a 2D java array?

I know that 2d arrays are arrays of arrays. To get a row you can do: rowArray = my2Darray[row] Since each row can be a different size, I'm assuming it's not built in to get a column from a 2D array. It leads me to believe you'd have to do something like: for(int row = 0; row < numRows; row++) { colArray[row] = m2Darray[row][colum...

Adding an element to an array from another class

This is probably an easy question but this is the first time i've encountered this. I have a modal view controller that I am getting a string from and need to add that string to an element of an array that is in another class that is calling the modal view controller. How do I pass and add that element from another class? Thanks... ...

How can I create a 2-dimentional matrix and feed information from arrays in Perl?

I have four arrays @A1, @A2, @A3, @A4 each with same number of elements, say 6. I want to create a 2 dimensional array which stores the values of two array elements I want output corresponding to following format. For example Array1: A B C D E F Array2: E F G H I J Array3: Q W E R T Y Array4: P O L I U G Then the Matrix should be: ...

How can I pin a byte array in Java?

Is there a way to pin a byte array in java, so it never gets moved/compacted? I am working on an application which is intended to have zero GCs during runtime, and I want to use primitive byte arrays that are pinned to a memory mapped area. Is there any way to do this or hack my way to it? ...

Reading sections from a file in Perl

I am trying to read values from an input file in Perl. Input file looks like: 1-sampledata1 This is a sample test and data for this continues 2-sampledata2 This is sample test 2 Data for this also is on second line I want to read the above data so that data for 1-sampledata1 goes into @array1 and data for 2...

(C#) Arrays, heap and stack and value types

int[] myIntegers; myIntegers = new int[100]; In the above code, is new int[100] generating the array on the heap? From what I've read on CLR via c#, the answer is yes. But what I can't understand, is what happens to the actual int's inside the array. As they are value types, I'd guess they'd have to be boxed, as I can, for example, pas...

C array pointer question

I thought that an array variable cannot be changed in C, i.e. the base address of an array is unchangeable, but the following code contradicts my assumption : #include <stdlib.h> #include <stdio.h> void changeArray(int **a) { *a = malloc(sizeof(int)); } int main() { int a[10]; a[0] = 1; printf("%d\n",a[0]); changeArr...

Using generics for arrays

Is it possible to use generics for arrays? ...

Moving every object in my array ?

I have an array an a timer that adds a new object to my array every 5 seconds but am running into a slight issue. I have a code that is called repeatably which moves the objects in my array but for some reason the previous object that spawns will stop moving when a new object is spawned into my array. How do I make it so every single obj...

Array initialization in F#

How do I create and initialize an array in F# based on a given record type? Suppose I want to create an Array of 100 record1 records. e.g. type record1 = { value1:string; value2:string } let myArray = Array.init 100 ? But it appears the Array.init does not allow for this, is there a way to do this? Edited to add: Of course I ...

Java Convert Object[] Array to Vector

What's the best way to convert an Object array to a Vector? JDE < 1.5 public Vector getListElements() { Vector myVector = this.elements; return myVector; } this.elements is an Object[] Thanks, rAyt I should clarify my question My target platform is a blackberry. Collections aren't supported. Array.asList() isn't, either :/ F...

Capturing output of find . -print0 into a bash array

Using find . -print0 seems to be the only safe way of obtaining a list of files in bash due to the possibility of filenames containing spaces, newlines, quotation marks etc. However, I'm having a hard time actually making find's output useful within bash or with other command line utilities. The only way I have managed to make use of th...

Hpricot CSS Class search

Hey guys. I am working on some code that scrapes a page for two css classes on a page. I am simply using the Hpricot search method for this as so: webpage.search("body").search("div.first_class | div.second_class") ...for each item found i create an object and put it into an array, this works great except for one thing. The search...

How to use a two-dimensional C array of Objective-C objects?

I have a two-dimensional C array of Objective-C objects. How do I access the members of those objects? id array[5][5]; array[0][0] = [[Ball alloc] init]; The Ball class has two members: int size; CGPoint point; How can I access size for the Ball object stored in array[0][0]? Please tell me how I can do this. Thanks in advance! ...

Pass Ascending/Descending option to uasort()?

Quick question: How would I switch the sort order between ascending/descending in the following function? All it does is order a multidimensional array by a chosen field, and then by title. $sortby = 'date'; $orderby = 'asc'; function sort($a, $b) { $retval = strnatcmp($a[$sortby], $b[$sortby]); if(!$retval) return s...

How to copy array?

Hello, I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR is local in the methods below,but usually it's a class var.Just for the concept it's local. class procedure TCelebrity.BeginRead(var input:Array of byte); var DataR:Array of byte; begin VirtualFree(@DataRead,High(DataRead),MEM_RELEASE); SetLength(D...

Help with dictionaries, arrays and plists on iPhone

Hi everyone, I would appreciate some help with something I working on and have not done before now and having some proplems because I don't think I understand exactly how to do this. What I'm wanting to do i'm sure is simple to most all of you and will be to me as soon as I do it the first time correctly....anyway.... I have a tableview ...