Consider the following piece of Java code.
int N = 10;
Object obj[] = new Object[N];
for (int i = 0; i < N; i++) {
int capacity = 1000 * i;
obj[i] = new ArrayList(capacity);
}
Because in Java, all objects live on the Heap, the array does not
contain the objects themselves, but references to the objects. Also,
the array itself ...
Hi, I was wondering if it is possible to declare an array (size not known at this time), as a private member of a class and later set the size in the constructor of the class. For example:
class Test {
int a[];
public:
Test(int size);
};
Test::Test(int size) {
a[size]; // this is wrong, but what can i do here?
}
Is this possible o...
I feel that it should be something very simple and obvious but just stuck on this for the last half an hour and can't move on.
All I need is to split an array of elements into N groups based on element index.
For example we have an array of 30 elements [e1,e2,...e30], that has to be divided into N=3 groups like this:
group1: [e1, ...,...
Given:
my @mylist1;
push(@mylist1,"A");
push(@mylist1,"B");
push(@mylist1,"C");
my @mylist2;
push(@mylist2,"A");
push(@mylist2,"D");
push(@mylist2,"E");
What's the quickest way in Perl to insert in mylist2 all elements that are in mylist1 and not already in mylist2 (ABCDE).
...
Say for example I have the following string:
var testString = "Hello, world";
And I want to call the following methods:
var newString = testString.Replace("Hello", "").Replace("world", "");
Is there some code construct that simplifies this, so that I only have to specify the Replace method once, and can specify a bunch of parameters ...
I'm trying to display the contents of an ordered array in something like a JTextField.
for (int i=0; i<array.length; i++) {
this.textField.setText(array[i]);
}
This won't work for two reasons. The first minor reason: if the array length is 4 then jtextfield is getting it's value reset 4 times rather than appending each element ont...
Using Managed C++ (VS 2005), how would you pass a array< unsigned char > to a function as a unsigned char*?
ref class Utils
{
public:
static void A(array<unsigned char, 1> a)
{
//How do I call B()????
}
static void B(const unsigned char* a)
{
//do stuff
}
};
...
I have a list of input words separated by comma. I want to sort these words by alphabetical and length. How can I do this without using the built-in sorting functions?
...
In the application I'm writing, one of the methods allows for the numbers the user entered to be turned into letters.
For example, the user will be entering grades (as doubles) and the program will decide (when the criteria is met) to return the letter associated with the number. Initially, I had it written like this:
public void GetGra...
I was shocked to find out today that c# does not support dynamic sized arrays, how then does a vb.net developer used to using redim preserve deal with this in C#?
at the beginning of the function I am not sure of the upper bound of the array, this depends on the rows returned from the database.
...
I have an array full of random content item ids. I need to run a mysql query (id in the array goes in the WHERE clause), using each ID that's in the array, in the order that they appear in the said array. How would I do this?
This will be an UPDATE query, for each individual ID in the array.
...
Hello,
In C# language when you refer to an array element you can write:
myclass.my_array['element_name'] = new Point(1,1);
I think about refering to a element with name element_name by using dot in place of backets:
myclass.my_array.element_name = new Point(1,1);
Do you know any language where exists similar syntax to the example ab...
My list (@degree) is built from a SQL command. The NVL command in the SQL isn't working, neither are tests such as:
if (@degree[$i] == "")
if (@degree[$i] == " ")
if (@degree[$i] == '')
if (@degree[$i] == -1)
if (@degree[$i] == 0)
if (@degree[$i] == ())
if (@degree[$i] == undef)
$i is a counter variable in a for loop. Basically it goe...
What is the purpose of the LongLength property for arrays in .Net. Using a standard integer for length, you could accommodate up to 2 billion indices. Are there really people using .Net to maintain a single array with more the 2 billion elements. Even if each element was a single byte, that would still be 2 GB of data. Is it feasibl...
I'm in a basic programming class, and everything is done in pseudo code.
My question is this: How do you link two arrays?
I have a single-dimensional array that lists students names, and I have a two-dimensional array that lists the top eight scores of each student...this is all fine and dandy, but now I need to sort the arrays by th...
I have an Array Collection with any number of Objects. I know each Object has a given property. Is there an easy (aka "built-in") way to get an Array of all the values of that property in the Collection?
For instance, let's say I have the following Collection:
var myArrayCollection:ArrayCollection = new ArrayCollection(
{id: 1, nam...
What's a nice way to merge two sorted arrays in ActionScript (specifically ActionScript 3.0)? The resulting array should be sorted and without duplicates.
...
I was working on some code recently and came across a method that had 3 for-loops that worked on 2 different arrays.
Basically, what was happening was a foreach loop would walk through a vector and convert a DateTime from an object, and then another foreach loop would convert a long value from an object. Each of these loops would store...
Perl seems to be killing my array whenever I read a file:
my @files = ("foo", "bar", "baz");
print "Files: " . join(" ", @files) . "\n";
foreach(@files) {
print "The file is $_\n";
func();
}
sub func {
open(READ, "< test.txt");
while(<READ>) {
}
close READ;
}
print "Files: " . join(" ", @files) . "\n";
produces:
...
What is the best way to ascertain the length (in characters) of the longest element in an array?
I need to find the longest element in an array of option values for a select box so that I can set the width dynamically.
...