arrays

2D Array Question Java

If I have a 2D array arr[rows][columns], how could I use arr.length to find size for rows and columns individually? ...

Array type in generics

I am trying to create an array of generic type. I am getting error: Pair<String, String>[] pairs; // no error here pairs = new Pair<String, String>[10]; // compile error here void method (Pair<String, String>[] pairs) // no error here. I am confused. Any clues why this is happening. ...

How do I get the output of an object which has more than one line in Perl?

@ver = $session->cmd("sh conf"); The variable here is ver, which has the configuration file, that is, it has more than one line. So how to take an output of each line of the ver variable without putting it in a loop? ...

How do I check if an array contains particular index in Pascal?

E.g. I have this array: type OptionRange = array[ 1..9 ] of integer; How do I check if array[x] exists? Actually, I want to limit user input with the array index. Am I doing the wrong thing? Is there a better practical solution? ...

NSCoding and integer arrays

How do you use NSCoding to code (and decode) an array of of ten values of primitive type int? Encode each integer individually (in a for-loop). But what if my array held one million integers? Is there a more satisfying alternative to using a for-loop here? Edit (after first answer): And decode? (@Justin: I'll then tick your answer.) ...

Fastest way to sort in Python

What is the fastest way to sort an array of whole integers bigger than 0 and less than 100000 in Python? But not using the built in functions like sort. Im looking at the possibility to combine 2 sport functions depending on input size. ...

getting null when reading a text file in java using buffered reader

I'm having a problem reading a text file in java and assigning it to an array. The program is running but I'm getting null. I tried changing the code to its simplest for just like what you see below. Because this one should really loop through the text file. But I'm doing it this way so that I will easily see where's the problem. But the...

Specify an Inline Array to Custom Attribute in VB.NET

I would like to know if there's any way to specify an inline array (lets say of strings) to custom attribute on a property in vb.net. I have the following example that doesn't compile in vb.net (.net 1.1): Attributes.ManyToOne(New String() {"a", "b", "c"})> _ Public Property PaymentTerms() As PaymentTerms The attribute is defined in ...

Check if C++ Array is Null

how do i do that? well i want to check if the array is empty ...

Removing extra "empty" characters from byte array and converting to a string

I was working on this for a while and did not find anything about this on here, so I thought I would post my solution for criticism/usefulness. import java.lang.*; public class Concat { public static void main(String[] args) { byte[] buf = new byte[256]; int lastGoodChar=0; //fill it up for example o...

Why this code doesn't works in Pascal?

I have this var: var UserInput : array [1..3] of string; I'm trying to set multiple values, at once. readln( UserInput[1], UserInput[2], UserInput[3] ); When the code runs, all the input is stored in UserInput[1] Ex.: Input: 10 1.5 18 Result: UserInput[1] = 10 1.5 18 UserInput[2] = 0 UserInput[3] = 0 What should I do? ...

Replacing items in an array

dbH = [] string = ("%s/t%s/t%s/t%s") % (i1, i2, i3, i4) originally, i1 = blah i2 = doubleblah i3 = tripleblah i4 = 0 ... how can I replace the value in i4 later on? ex. right now dbH[1] = ("Adam\tJack\tJill\tNULL") later on dbH[1] = ("Adam\tJack\tJill\tJohn") ...

How to Handle Consuming Lots of Data from Multiple Sources in a Web SIte

This is a "meta" question that I am asking in a effort to better understand some tough nuts I've had to crack lately. Even if you don't get precisely what I'm reaching for here or there is too much text to read through, any practical input is appreciated and probably useful. Assume you have a website that needs to use data that is store...

Hide elements that are in an array | jQuery

Is it possible to hide elements that are in an array, e.g. var elements = ['.div-1', '.div-3']; With a structure of: <div id="wrap"> <div class="div-1"></div> <div class="div-2"></div> <div class="div-3"></div> </div> So div-2 should stay visible, while the elements that are in the array would be hidden by fadeOut. Is t...

javascript array sorting ?

Given the following array: var things = ['sandwich', 17, '[email protected]', 3, 'horse', 'octothorpe', '[email protected]', '[email protected]']; Sort the array into three others, one of numbers, one of strings, and one of valid email addresses. Discard the invalid address. ...

Ruby Get Array From Objects Returned in a Block

In Ruby, on certain occasions (ruby/gosu/texplay) I'v seen code like the following used: image.paint { circle 20, 20 pixel 10, 10 } Would it be possible for me to write a similar function that can be used like so?: my_function { "one" "two" "three" } that would return and array: ["one", "two", "three"] p.s...

Java array question..

I have a 3x4 array that I want to rotate left once, so that it becomes a 4x3. Imagine a box of values, and just rotate that box left. Here's the function I wrote: public static int[][] rotLeft(int[][] source) { int[][] newImage=new int[source[0].length][source.length]; for (int i=0;i<source.length;i++) for (int j=0;j<sou...

Change order of elements in Rails association collection

If I have a collection of objects through a 'has and belongs to many' association in Rails (e.g. the album 'summer photos' has a collection of photos), how can I arbitrarily change the order of the elements in that collection? For example, there is a default index that would yield @album.images[0] or .first. how would I go about ch...

Visual Basic: How to declare an array of array ?

Hi there. I've googled this question several times, but I can't find something that works. I want to declare an array of arrays (arrArr) of unspecified length. Actually, I work with Excel: if the sheet exists, fetch its array and store it in the array of arrays. I've declared this arrArr like this, and the program basically works this ...

Help trying to generate tricky multidimensional array format

Hi guys, I'm having trouble trying to build an array in PHP which will output in the JSON format I am looking for. I will show you what I am trying to achieve and where I have got to so far: [ {"data":[{"x":3,"y":0},{"x":10,"y":0}]}, {"data":[{"x":11,"y":0},{"x":13,"y":0}]}, {"data":[{"x":12,"y":1},{"x":17,"y":1}]} ] I am ...