Questions tagged [arraylist]
A simple collection data type found in some languages / platforms (such as in Java or .NET). The array list implements a list using an array, benefiting from both the DSs strengths.
33,517
questions
0
votes
1
answer
28
views
How can I loop through and sort a nested ArrayList based on the first element in the sub-ArrayLists?
For example:
a = [jamie, 3, 5, NY]`
b = [Barney, 2, 3, FL]
c = [Thomas, 4, 6, TX]
d = [Darnell, 5, 6, NC]
unsortedArrayList = [ [jamie, 3, 5, NY], [Barney, 2, 3, FL], [Thomas, 4, 6, TX], [...
0
votes
1
answer
28
views
Why second parameter of objects in array list are overwritten by adding new object to array list? [duplicate]
I would like to get data from a CSV file. First entry is name of user, others are values. Everything works, but when I create new User object (name and bills parameters) and add it to ArrayList of ...
-4
votes
3
answers
35
views
How to access variable inside array Inner arrays [closed]
{
"NoOfPages": 0,
"CurrentPage": 0,
"ArrayOfResponse": [{
"personalDetails": [{
"active": [{
"...
-3
votes
0
answers
26
views
Iterating through Map and Printing it
public void printBookingDetails() {
System.out.println("Your Booking Details are : ");
Set<String> keys = map.keySet();
System.out.println("Part 1 of displaying");...
0
votes
0
answers
10
views
How to convert list(string) to Python's set format in Terraform
I would like to apply a variable as a resource's argument, using Python's set format syntax of {"element-1","element-2",...}. A guiding principle is to let the end-user load the ...
1
vote
2
answers
32
views
Remove value from nested array item react native
I have below array format:
[
{
"category": "c8kr0cv012vtr8vm3iqg",
"subcategories": [
"c8kr3d7012vtr8vm3jm0",
"c8kr3d7012vtr8vm3jlg&...
1
vote
7
answers
63
views
Checking multiple conditions in an array - Java
I'm writing a function to check multiple conditions in an array, if they are all true then return true.
For example:
public class Attribute {
private final String key;
private final String ...
0
votes
0
answers
16
views
Want to create csv file and write to csv file using multiple different arraylists
I have 5 ArrayLists at the moment:
ArrayList <String> name;
ArrayList <Integer> age;
ArrayList <Integer> salary;
ArrayList <String> address;
ArrayList <String> occupation;...
0
votes
2
answers
34
views
How to use generics for type safety while using `removeRange` method of ArrayList
Since the method - removeRange(int startIndex, int ) is protected, we need to use it in a class extending ArrayList. Below is my code -
public class MyClass extends ArrayList<String> {
...
-1
votes
1
answer
22
views
Getting IndexOutOfBounds exceptions with Arraylist in a Loop
I am making a game similar to Worldle.
I am trying append input to an Arraylist each time the loop executes.
While also trying to keep the format of wordle (testnum and testnum2). I am quite new to ...
1
vote
1
answer
62
views
What is the benefit of setting the capacity of an ArrayList explicitly [duplicate]
In java ArrayList we have a constructor -
ArrayList(int capacity)
and two methods -
void ensureCapacity(int minCapacity)
void trimToSize()
Consider a code-sample:
ArrayList<String> arrayList3 = ...
0
votes
0
answers
17
views
The efficiency when implementing a dataframe using java: list of row VS. list of column?
I'm going to write a piece of code that accepts a list of String, then splits each string into a list by delimiter (now there is a data frame). then I'm going to get a specific column as a list, ...
0
votes
1
answer
22
views
AlpineJS async call to render array of objects
Having the following snippet trying to fill an array of object with async alpine call but I can not get any result. Hier is what I try.
HTML:
<div x-init="experts.retrieveList" x-data=&...
-4
votes
1
answer
43
views
How to turn a 1 dimensional arraylist to 2 dimensional arraylist Java [closed]
From:
[xxxxxx,xxxxxx,xxxxxx]
To:
[[x,x,x,x,x,x],[x,x,x,x,x,x],[x,x,x,x,x,x]]
Is there a more efficient way to turn this arraylist to a multidimensional arraylist?
0
votes
3
answers
36
views
Java List auto create and add
Is it possible to replace this:
if (archiveUnitEntity.getArchiveCaseEntityList() == null) {
archiveUnitEntity.setArchiveCaseEntityList(new ArrayList<ArchiveCaseEntity>());
}
...
0
votes
0
answers
11
views
How to collect data from array loop
My Array :
array(1) {
[0] => int(9)
}
array(1) {
[0] => int(86)
}
I want array sum int(9) + int(86) how can I do it ?
echo 95 //
0
votes
2
answers
58
views
Java ArrayList of type Interface
I have two java endpoints in spring boot like this:
@PostMapping(path="/my-import-1")
@ResponseStatus(HttpStatus.OK)
public String myImport1(@Valid @RequestBody ParameterDto1 params) {
...
-5
votes
1
answer
70
views
My login method returns both true and false output, why?
I still cannot figure out what is wrong with my code.
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("[1] Register&...
0
votes
2
answers
23
views
Listview for Multiple model class
how to create a listview adapter on Android Studio(Java) for multiple model class which extending parent class.
so :
gbpClass extends Money => ArrayList
eurClass extends Money => ArrayList
I ...
2
votes
1
answer
47
views
Why there are different huge about efficiency between access array and ArrayList element
I make a testing like this:
int target = 100000000;
ArrayList<Integer> arrayList = new ArrayList<>();
int[] array = new int[target];
int current;
long start, getArrayListTime, getArrayTime;...
0
votes
0
answers
27
views
How to populate an ArrayList as a property inside a class using jdbc?
I have a frame which has two JComboBoxes and a Rent Button. One ComboBox contains an arraylist of a class called Movie. The other ComboBox contains an arraylist of a class called Member which has a ...
1
vote
0
answers
36
views
Problems with a list…
I am new in Python and I need to access a csv file that I have in a folder. This is not a problem:
open(‘C:\Users\Directory\companies.csv’)
I have tried this:
from csv import reader
# read csv file as ...
-2
votes
0
answers
11
views
MadLib Nested User Input loop [duplicate]
The current issue that the user is supposed to choose if they want to do a Madlib then would be asked to choose a number for a lib, put inputs for the mad lib and output the final lib and ask if the ...
-1
votes
0
answers
21
views
How would I go on about making a while/for loop taking user input for a class? [duplicate]
So I'm making a school database where you can enter a Student's information (Name, ID, Grade) through a class, but I just ran into a problem, how would I make a loop for someone to enter a student's ...
1
vote
3
answers
35
views
Get the key of an hashmap when the values are list
I have a list of orders(order id) List<Integer>order with Integer values in it.
I also have a Hashmap of the form <String, List<Integer>> which contains the customer names as keys ...
0
votes
2
answers
53
views
Use Class parameter for generic type (e.g ArrayList)
I am trying to create a generic method to handle different types of ArrayLists in Java. The types are quite different, but all contain one identical parameter, which I want to evaluate in this method.
...
0
votes
2
answers
57
views
Finding the third largest string from an array of strings in Java
One of my friends asked me about a coding challenge that their lecturer gave them as an exercise. I got a solution working to solve it. But I think the solution is too lengthy for a categorised ...
-1
votes
2
answers
34
views
Java - How to replace entire 2D ArrayList with another that has different size
I have 2D ArrayList consisting of Objects, i pass it to a function in another class, like this:
public void function(ArrayList<ArrayList<Object>>)..
class.function(array)...
then inside ...
2
votes
2
answers
39
views
Accessing specific elements in Arraylist of Objects
Really confused on how to access just the age of a specific student where all the information of students have been stored in a textfile. I am reading the textfile and storing that info into a student ...
0
votes
1
answer
35
views
How can I create a two dimensional array with each element being a list in Java?
I want to create a two-dimensional array, each element of which is a list, as in the image.
I tried ArrayList<List<User>>[][] arrayList = new ArrayList[3][3];
Is this a correct solution? ...
0
votes
0
answers
29
views
Is it possible to multiple a array state without its value? [closed]
I have two arrays:
const a = [6,4,5,3];
const b = [10,20,30,40];
Is there a solution to get a new array by multiplying arrays a by b instead of getting their values multiplied?
I.e: I want their ...
0
votes
1
answer
18
views
I was trying to solve "Grid unique path" using Dynamic programming in Java
I am trying to implement a solution for grid unique path using D.P. approach while trying to do so, I don't know why in the middle of execution the value at (0,1) location gets negative while I'm ...
-1
votes
1
answer
25
views
How to Initialize 2d ArrayList with 0 in one line
How to Initialize all the element of 2d Array List in Java with 0 in single line of code without using for lop.
ArrayList of m rows and n columns.
How to initialise value of all the elements to 0 at ...
0
votes
2
answers
47
views
Arraylist sum 5x5 [closed]
I need to calculate by adding the values of the elements above, below, left and right of that element to the value of that field.
It is a 5x5 list
ArrayList<Integer> niz = new ArrayList<...
-1
votes
2
answers
26
views
JavaScript - How do I print an input inside an array? [closed]
I already tried many ways to solve this, but it always returns undefined. What should I do to solve this issue?
function printThreeFavoriteColours() {
const colours = [];
const colorUserFav1 = ...
0
votes
1
answer
32
views
Reading Latitude and longitude from CSV file and display in google map after applying filtering to a column
I managed to fetch long and lat values from CSV and loop them to display all values in google map .Now i need to filter column Fuel_Type = "Unleaded 91" how to add this to while loop ?
while(...
1
vote
1
answer
27
views
How do I separate items in an arraylist by character in Java?
I'm working on a game of Go Fish for a school assignment and I need to separate a group of 4 cards in order to keep score. Any help would be greatly appreciated
import java.util.*;
import java.io.*;
...
0
votes
1
answer
29
views
Filtering array list
I have a class which I want to use, to filter my array according to driver. Driver is hardcoded just to try and eliminate possibilities of why the code is not working. I have tried a lot of different ...
-3
votes
0
answers
33
views
ArrayList question... that seems to be a challenge to many [duplicate]
I have a tiny tiny problem that I seem incapable to solve by Googling.
I want to add Tabels (a class I made up) to an array.
I tried below method in code and I also tried these variants
This: ...
0
votes
0
answers
8
views
Best way to sort BOTH prefix and suffix with custom sorting
So I have a list of codes, something like:
(I.-)
(I.+)
(I.0)
(B.+)
(B.0)
(B.-)
...
(No value)
(N/A)
I was able to sort them but we have a "custom requirement" that "-" comes before ...
0
votes
2
answers
37
views
searching in arraylist always not found
no matter what I use indexof() or contains or .equals() changing everything to uppercase or to lowercase It always return false and not found can someone please tell me what is going on?
class ...
-4
votes
0
answers
12
views
i am starting in programation and ai need complete the constructor in this class, but i dont get how to include objects into arrayList [closed]
import java.util.ArrayList;
public class ListaPersona
{
private ArrayList listaPersonas = new ArrayList();
public ListaPersona()
{
}
public void llenarLista()
{
int peso;
for(int i=0;i<5;...
0
votes
0
answers
15
views
ResultSet.next loop saving only the last row in the arraylist [duplicate]
So I have a table in SQL with three columns, Clan_id, Ime and Prezime. The table has 15 rows. I also have an ArrayList of Clan class called "clanovi" and a Clan model. I want to select all ...
-2
votes
2
answers
38
views
Unity C# error: (12,47): error CS1503: Argument 2: cannot convert from 'System.Collections.Generic.List<UnityEngine.GameObject>' to 'float'
I'm new to programming in general.
With another Script i store in the list "spawnPointC" all gameobjects called spawnPointC that appear from spawning other prefabs.
I want to pick a random ...
0
votes
1
answer
25
views
How to change the key of JSONArray in java
JSON received by POST from the front end
[{"id":"001","name":"James"},{"id":"002","name":"Emma"}]
I want to change the ...
0
votes
0
answers
44
views
How to turn list in other way? Java arraylist
Write a program that runs a string of lengths N, so that loading elements into string a is the other way around.
thhis is my code:
ArrayList<String> niz = new ArrayList<String>();
System....
-1
votes
0
answers
12
views
Search an array list inside another array and return a new object combined
I am using typescript and I have two objects:
export interface Module {
moduleId: String
name: String
}
export interface Model {
id: number
name: String
modules: Module[]
}
I have ...
-2
votes
0
answers
20
views
Display A Random Quote and Author from Array List in a New activity On Button Click
I'm trying to create a mood checker application. Where when the user clicks on a mood, it would display a quote in a new activity. My application runs but the quote is not displayed. I think there ...
-1
votes
0
answers
38
views
Arraylist not able to be called inside another method
private ArrayList<Note> retrieveNotes() {
ArrayList<Note> tempNotes;
db.collection("Note")
.whereEqualTo("subject", "Subject1")...
0
votes
0
answers
5
views
When arraylist prints objects from 2 classes how to make it print objects from only 1 class
I have this class called Training that extends the other 2 classes
public class Training{
public int workoutTime;
public String typeOfWorkout;
public Training(){
}
public Training(int workoutTime, ...