arrays

What type is System.Byte[*]

I'm being passed an object that returns "System.Byte[*]" when converted to string. This apparently isn't a standard one dimensional array of Byte objects ("System.Byte[]"), so what is it? ...

PHP: How to remove specific element from an array?

How do I remove an element from an array when I know the elements name? for example: I have an array: $array = (apple, orange, strawberry, blueberry, kiwi); the user enters strawberry strawberry is removed. To fully explain: I have a database that stores a list of items separated by a comma. The code pulls in the list based on a u...

C# Array or Dictionary?

Hi. I wanted to know is C# array has a constant access speed? I need to store 1000 items in static array, that will be initialized during server startup. This array will be used readonly, so there will be no changes to array. Should I use a simple C# array (new MyClass[]) or Dictionary instead. I am really new to C# and trying to unders...

Getter/setter on javascript array?

Is there a way to get a get/set behaviour on an array? I imagine something like this: var arr = ['one', 'two', 'three']; var _arr = new Array(); for (var i=0; i < arr.length; i++) { arr[i].__defineGetter__('value', function(index) { //Do something return _arr[index]; }); arr[i].__defineSetter__('value', function(index, val) ...

Ruby: How to loop through an object that may or may not be an array?

I have an each method that is run on some user-submitted data. Sometimes it will be an array, other times it won't be. Example submission: <numbers> <number>12345</number> </numbers> Another example: <numbers> <number>12345</number> <number>09876</number> </numbers> I have been trying to do an each do on that, but whe...

Java HashSet<Integer> to int array

I've got a HashSet with a bunch of (you guessed it) integers in it. I want to turn it into an array, but calling hashset.toArray(); returns an array of Object type. This is fine, but is there a better way to cast it to an array of int, other than iterating through every element manually? A method I want to pass it to void doSomething...

PHP function generate UL LI

hi.. i'm referring this address for function olLiTree http://stackoverflow.com/questions/753853/php-function-that-creates-a-nested-ul-li i have this array $tree = array("A"=>array("B"=>array("C"=>"C","D"=>"D"),"E"=>array("F"=>"F","G"=>"G"))); but not able to use this function function olLiTree($tree) { echo '<ul>'; for...

Python: Create a duplicate of an array

I have an double array alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a seperate double array (no shared pointers) without having to do a double for loop? Thanks, Da...

Weird compile-time behavior when trying to use primitive type in generics

import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[]) Array.newInstance(componentType, 0); } public static void main(String args[]) { int[] intArray; Integer[] integerArray; intArray = (int[]) Array....

Help getting array from arrays.xml file (Android, Eclipse)

I am just trying to display a list from an array that I have in my arrays.xml. When I try to run it in the emulator, I get a force close message. If I define the array in the java file (String[] testArray = "one","two","three","etc";) it works, but when I use "String[] testArray = getResources().getStringArray(R.array.testArray); " it ...

Java - converting String in array to double

I'm stuck with this pretty silly thing; I got a textfile like this; Hello::140.0::Bye I split it into a string array using; LS = line.split("::"); Then I try to convert the array values containing the number to a double, like this; Double number = Double.parseDouble(LS[1]); But I get the following error message; Exceptio...

Finding the index of a given value in a pre-sorted array

Today, I went for an interview and the interviewer asked me how I would find the index of a given value (number) in a pre-sorted array like this: $preSortedArr=array(23,32,36,41,45,54); He also said that using recursion is not allowed. I think the function should look like this: function findIndexByValue($preSortedArray,$value){ ...

Does casting an IList<T> to an array of type T[] cause enumeration?

I have a method that looks like: T[] field; public Method(IList<T> argument) { this.field = (T[])argument; } When the body of the method is executed does enumeration take place during the cast? Would that change if the underlying type was different? ...

Find maximum occuring integer (Mode) in an unsorted array

How to find the integer occurring maximum number of times (mode) in an unsorted array of integers? One O(nlogn) approach I could think of is to sort. Is there any other better approach? ...

Are stack based arrays possible in C#?

Let's say, hypothetically (read: I don't think I actually need this, but I am curious as the idea popped into my head), one wanted an array of memory set aside locally on the stack, not on the heap. For instance, something like this: private void someFunction() { int[20] stackArray; //C style; I know the size and it's set in stone }...

Java - problems with polymorphism

I have a book class, then a novel- and a science book class that extend the book class. I made an ArrayList using the book class, then inserted the novels and the science books into that. Now I'm trying to iterate through the ArrayList to count how many novels are there. How can I tell? Would love to see some examples of this! I've bee...

Recursion with an Array; can't get the right value to return

Solution found - in under 5 minutes, thanks folks! Clarification: The contents of my array are the values 0-29. So array[0][0] = 0, while array[29][0] = 29 --- they're just test values. Also, I have a potential solution that's been posted multiple times, going to try that. Recursive Solution: Not working! Explanation: An integer, ti...

PHP Compare Two Arrays?

I'm trying to compare two entries in a database, so when a user makes a change, I can fetch both database entries and compare them to see what the user changed, so I would have an output similar to: User changed $fieldName from $originalValue to $newValue I've looked into this and came accross array_diff but it doesn't give me the outp...

How do I get the inner arrays length in a 2d array in C#?

Lets say I create a jagged 2d array like so: public static char[,] phoneLetterMapping = { {'0'}, {'1'}, {'A', 'B', 'C'} }; Now, given the first index of the array, I would like to be able to get the length of the inner array. So, I would like to be able to do something like: phoneLetterMapping[2].length I can do that in Java. But...

Change size of 2D dynamic array in C

I create a 2D dynamic array: a = (int**)calloc(n-1, sizeof(int)); for(i = 0; i < (n-1); i++) a[i] = (int*)calloc(n, sizeof(int)); Then I need to change its size (add new line): a = (int**)realloc(a, n); a[n] = (int*)calloc(n, sizeof(int)); But when i want to print my array, void Print(void){ int i, j; for(i = 0; i < (...