Most voted "array" questions
An array (array, vector, or matrix) is an ordered data structure representing a collection of elements (values or variables), each identified by one or multiple indices.
Learn more…3,046 questions
Sort by count of
-
10
votes5
answers12645
viewsHow to create a vector without determining its size in Java?
I have a class TesteAplicacao that is to test and a class Teste with attributes and methods. When creating a vector in Java: Teste[] t = new Teste[10];// veja que teve definir um tamanho It would be…
-
10
votes3
answers2010
viewsHow to optimize the sum of elements in an array
I need to get the sum of the items of a array javascript. The quantity of these items can easily reach 2,000 items. The items are of the type int, no need to test. ar = [1,3,5,...,2000]; I already…
-
10
votes1
answer2100
viewsDifference between Std::list, Std::vector and Std:array
All are containers used for data guards in a sequential manner, but what are the main differences between them?
-
10
votes3
answers13554
viewsConvert object array to array arrays
How to perform string conversion (object array): [ {"id":1,"nome":"Maluf","cpf":"007.519.591-20"}, {"id":2,"nome":"Paulo Ricardo","cpf":"565.232.591-02"}, {"id":3,"nome":"Joaquim…
-
10
votes4
answers333
viewsHow to manipulate these objects with Javascript?
I have the following objects: { letter: "A", num1: "1", num2: "2", num3: "3" } { letter: "B", num1: "3", num2: "2", num3: "1" } { letter: "C", num1: "2", num2: "3", num3: "1" } I would like to…
-
10
votes4
answers985
viewsCompare string with array to return the most compatible item
How to compare to string with the array and return whatever has more compatible words? Example: string = "uma frase qualquer aqui" array = ["frase qualquer", "uma qualquer aqui", "nada compatível"]…
-
9
votes7
answers7922
viewsConvert an array of floats to integer
Suppose the following: import numpy as np a = np.array ( [1.1, 2.2, 3.3] ) How to convert this array to int without having to iterate each element or using another array? Why do: b = int(a) Gives an…
-
9
votes1
answer1038
viewsIs there a data structure like an associative array in Java?
Well, I’m wanting to name an Array of Strings in Java, but I wanted it to be, for example: String[] symbols; And could be declared so: symbols["name"] = "Tiago"; I know there’s no such Array, but…
-
9
votes2
answers3515
viewsRemove more than one item from an array
It is possible to remove more than one item from an array at a time. Follows the code: var teste = [6,4,5]; //meu objectivo é remover os itens 4, 5 por ex //removendo o item 4 teste.splice(1, 1)…
-
9
votes6
answers8412
viewsFunction that enumerates letters of the alphabet
How to convert alphabet letters into one array of numbers according to its sequence? The array should start from paragraph 1, not zero. So the letter A valeria 1, B valeria 2, C valeria 3, and so…
-
9
votes2
answers229
viewsuser tree with dots and profile in C#
I have a list of users in which each has a sponsor (sponsor is also a user). Each user has points and is of one type. I want to know which branch of the tree has the highest number of points and for…
-
9
votes8
answers794
viewsMapping an array with possible subarrays as elements
I am trying to create a function that files an array to another newArray. If one of the array elements is an array, I want to map all its subelements to newArray. Therefore: var array = [1,2,3,4,5,…
-
9
votes3
answers253
viewsIs there a "in" comparator operator in Javascript?
In Javascript there is a way to use in to check whether the value of a variable is contained in a list of values? A visual example: if (tipoDemissao in [1, 2, 5]){ valorDemissao = 525.20; }…
-
9
votes1
answer1218
viewsSort numeric vector without using Bubble Sort
We usually learn in college that, to sort integer vectors, we use a technique called Bubble Sort: int[] vetorOrdenado = new int[8]; vetorOrdenado[0] = 2; vetorOrdenado[1] = 41; vetorOrdenado[2] =…
-
9
votes1
answer542
viewsWhy do we use parentheses in a pointer statement?
What is the difference between these two statements? int* array1[10]; int (*array2)[10]; Why are there parentheses in the second?
-
9
votes6
answers300
viewsHow do I transform an array that is in a string for javascript array?
I have a string representing an array as follows: var = "['aaaaa', 'bbbbb', 'ccccc', 'ddddd']"; Wish I could transform this array that is in the string into an Array to perform manipulations. var =…
-
9
votes2
answers785
viewsArraylist versus List
Why in C# we should prefer to use the List instead of ArrayList?
-
9
votes1
answer119
viewsHow does PHP arrays work internally?
PHP handles arrays in a way different from other languages, apparently there are concepts of hashtable to associate values. How it works internally in the core language arrays?…
-
9
votes3
answers2052
viewsConvert a comma-separated string to a multidimensional array
I have a string thus ... var listAdd = "1789, 3, 8 , 1788, 3, 8, 1790, 3, 9" How do I convert into a array as below? [1789,3,8], [1788,3,8], [1790,3,9] The code I’m trying isn’t working: var…
-
9
votes1
answer144
viewsWhy Arrays and Functions are Objects?
I learned that objects store properties and methods: let objeto = { propriedade: "valor da propriedade", metodo: function() { return "retorno" } } But I see sites calling functions and arrays of…
-
9
votes3
answers566
viewsHow does Python handle and represent an array internally?
In Python any type of array is of class type list, see: array = ['Gato', 'Jake', 'Finn'] print(type(array)) Exit: <class 'list'> That is, every array is an object of list. However, there is…
python array characteristic-language python-internals cpythonasked 5 years, 9 months ago gato 22,329 -
8
votes2
answers673
viewsHow to quickly recover a large PHP array?
In the example below, I have a array in PHP with about 128,000 records (Portuguese language entries) that I retrieved from another file, and use in some applications, to compare the indexes as…
-
8
votes2
answers633
viewsSort array by a property
I am trying to sort an array by a specific property(weight), I found some possible solutions but they did not work for my case, someone would know where I am doing something wrong or another way out…
-
8
votes2
answers3219
viewsC++ - Size of an array pointer
I have an array: char *exemplo[] = {"item1", "item2", "item3"}; And a function: void myFunc(**myArray) { } So, I want a function that returns the size of this array that I passed as parameter. For…
-
8
votes1
answer7678
viewsHow to make a function within a function return a vector?
I have a job for my course, and it is necessary to make a program similar to the game of megasena. It’s almost done, but I’m finding a small problem and I need help. Job dice: maximum 10 players can…
-
8
votes1
answer410
viewsMatrix parameter passing error
I am trying to understand the function of pointers for an array. For this, I have elaborated the small program below. I made some mistake, because, in the indicated line, error is occurring…
-
8
votes3
answers1135
viewsHow to make the first two numbers of a sequence Math.Andom are NOT EQUAL
I made a lottery system in order to learn, I will not post the entire code here just the part I’m stuck. The PC draw is a sequence of 6 numbers that I present in the DOM (that doesn’t matter), so I…
-
8
votes2
answers193
viewsHow does a variable point to a pointer?
Reading this answer on pointers and arrays in C, there is the example below where the variable ptr points to the first element of this array. int array[42] = {42}; int *ptr = a; How this pointer…
-
8
votes1
answer2823
viewsWhat does i-esimo mean in an array?
Which means i-th, I’m having a hard time understanding its use in arrays and matrices.
-
8
votes1
answer156
viewsTo create a function equal to C# Array.Copy in C++
I would like to create a function similar to Array.Copy from C# to C++. This function has the prototype thus: public static void Copy( Array sourceArray, int sourceIndex, Array destinationArray, int…
-
8
votes3
answers3514
viewsHow to store any string in C?
How do I store a string (input) without knowing the size of this string, for example: #include<stdio.h> int main (){ char nome[]; /* a array não tem tamanho determinado porque o input ainda…
-
8
votes1
answer80
viewsCan you initialize only a few members of a C array already in your definition?
I know you can do this: int a[5] = { 0, 3, 8, 0, 5 }; or int a[5]; a[1] = 3; a[2] = 8; a[4] = 5; Can you do the same in just one line, already in the definition? IE, you can initialize only a few…
-
8
votes4
answers3416
viewsHow to do a search to know if a string is inside a vector in C#
I’m doing a little program that searches inside a vector. The problem I’m having is that if he finds the name he gives a message saying it was found but then gives another message saying that it was…
-
8
votes2
answers1802
views -
8
votes1
answer514
viewsCount sequences of 1 within vector in R
I would like to know how to count sequences of 1 within a vector containing only 0 and 1. For example, in the vector x <- c(1, 1, 0, 0, 1, 0, 1, 1), the count would give the vector (2, 1, 2),…
-
8
votes2
answers105
viewsHow does an array of functions recognize the position of the next element?
Why do you ask: The question may seem strange, but is that I am a beginner in programming and at this moment I am studying pointers to function and in an example in the book by which study is…
-
8
votes1
answer186
viewsHow to filter multiple items within an array
I have the following JSON: { "Empresas": [{ "Name": "DIST", "Portais": [{ "title": "PRD", "tags": ["PRD", "DIST1"] },{ "title": "HIST", "tags": ["PCP", "DIST2", "DIST3"] }] }, {"Name": "LUZ",…
-
8
votes1
answer147
viewsWhat is the equivalent of Python’s dir function in Javascript?
I was looking for a javascript function equivalent to the function dir python. In Python, if I want to see all methods associated with a given object, just pass the function dir directly to…
-
8
votes1
answer110
viewsWhy, in C, is a statically declared array name not an lvalue?
Why, in C, the name of a statically declared array is not a lvalue? A lvalue is an expression that can appear on the left side of an assignment statement. It is an expression that represents a…
-
7
votes4
answers12949
viewsReturn Array with name of all files in directory
I need my HTML5 page to return a Array with all existing file names and extensions in a directory within my site. I can do this in other server-side languages, but I would like to do it in JS. there…
-
7
votes3
answers24936
viewsLast position of an Array
In PHP, what is the fastest and easiest way to get the last position of an Array? I got it by doing $array[ count($array) - 1 ], and it works, but there’s some way simpler and less ugly?…
-
7
votes2
answers3113
viewsHow to pick a random string from a list of strings?
Code: nomes = new string[5]; nomes[0] = "José"; nomes[1] = "Carlos"; nomes[2] = "João"; nomes[3] = "Miriam"; nomes[4] = "Estela"; I put an array, but it doesn’t have to be with an array, it can be…
-
7
votes3
answers4546
viewsHow to make a foreach for an array of arrays?
How can I make one foreach for an array of arrays like this: array ( [option1] => 2 [option2] => array ( [name] => "ola mundo" [id] => "123456" ... ) ... ) The array can vary from…
-
7
votes4
answers28233
viewsHow to know the highest value of an Array?
I am making 1 calculator that adds values typed by the user and when the values of sums arrive in 1000 or exceed, the loop ends. So far so good, the problem is to be able to identify the largest…
-
7
votes2
answers5339
viewsRemove empty positions from an array
I’m passing a array via GET for PHP and then send it to the client side (Javascript). When I receive it it looks like this: m_prod = [5,,,,,,,,6,,,,,,]; In other words, it is including a space in…
-
7
votes3
answers823
viewsAssign array type in PHP
I know PHP is a weakly typed language. But there is some alternative way to "type" a array in PHP? Example, I can do this below to force receive a specific type of data in a function. function…
-
7
votes3
answers1181
viewsPassing vector to functions
How do I pass a vector to a function? Something that, on the Moon, would be like this: vector = {"V", "e", "t", "o", "r"} function getVector(vector, pos) return vector[pos] end…
-
7
votes2
answers7907
viewsConvert XML to PHP array
I’m fetching article names by this link:…
-
7
votes1
answer11081
viewsRemove duplicate elements in Array
I’m getting an array by JSON, and using the array_unique to remove duplicated values, however, is displaying the following error: <b>Notice</b>: Array to string conversion in…
-
7
votes4
answers658
viewsHow to test the condition on a vector?
I have to make a program that reads a text, where each first letter of each word in the text is replaced by a character (*). I cannot compile correctly, I believe the problem is in my condition…