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.

7
votes
6answers
117 views

ArrayList internals

TL;DR Why is ArrayList using different constructors allocating space and increasing that space at a different pace? I seem to stumble across something interesting in ArrayList implementation that I ...
0
votes
2answers
37 views

java retrieve original element from object

I'm new to java and what I'm currently trying is. For example I have 2 classes 1 for Employees which can have a name number and email and one for Vehicles which have number type and status. I ...
1
vote
1answer
50 views

How to remove entire list but left only last index

I'm in condition that requires 1 list to be always filled one by one and I want to delete the entire list but left it with only last index I've been trying with these snippets. But it delete the ...
1
vote
3answers
41 views

How to add multiple values in add method of array?

I am trying to add multiple values to an array, but it returns a cannot resolve error. Is there any way or work-around here? for (Map.Entry<String,String> entry : hash.entrySet()) { ...
0
votes
3answers
32 views

What happens with the ID's of the elements after deletion?

Let's say I have a LinkedList with 20 elements, starting id from 0 to 19. When I remove the first 10 elements from the list, what will be the value of the ids of the remaining 10 elements. Or if ...
0
votes
1answer
24 views

Array loop all null values function in VueJS

I want to filter my array_values all those has last_login = null . How to loop the values from array and store into variable along with the said last_login = null data in VueJS? Array values to be ...
0
votes
3answers
49 views

How to return a random value within a range, from a Map with Integer and List of Longs in Java

I am trying to find a way to get a random value from a provided list of different ranges using ThreadLocalRandom, and return that one random value from a method. I've been trying different approaches, ...
-1
votes
1answer
49 views

How do i get an element from List<T> elements= new ArrayList<>();?

I want to get the elements from the list. I'm working right now on a project, next to the Class name is: <T extends Comparable<T>> written. And I do have a ArrayList List<T> list ...
0
votes
0answers
6 views

How to make an Arraylist with images and display these images one after another into a JLabel with a delay of 2 seconds between them?

I'm trying to make a JLabel with images which display one after another periodically (with a delay of 2 seconds between them) and I don't know how to do it. Firtsly, I put those images in my project ...
0
votes
1answer
35 views

Why we can use methods of ArrayList without creating new ArrayList object?

We have to create a object of any class to use their funtionalities unless those are static functionalities. But why we dont need to create a ArrayList object to use its methods like add, contains etc....
0
votes
1answer
20 views

Customizing Array of Query response

I have a JSON response to be customized to our need The response is like below which contains multiple arrays with data but i want to sort out single category like MAIN and display all related ...
1
vote
0answers
45 views

Calling Stored Procedure With List Parameter

I am unable to figure out how to send a list as a parameter to SQL Server Stored Procedure using myBatis call sp(List<Object>) I have a stored procedure inside a SQL Server(2012) which ...
0
votes
1answer
13 views

ArrayLIst to a JSON file

I have an arrayList of linkedHashMaps. Now I want to write the arraylist to a json file as shown below. { "results" : [ { "key1" : "value1", "key2" : "value2" ...
0
votes
2answers
58 views

How do you sort an ArrayList of entities by their Y-value? [duplicate]

I am making a game where I can spawn soldiers with a button click. All of these soldiers will be added in an ArrayList named entity_walking_right_array. I also have another ArrayList for the entities ...
-3
votes
3answers
64 views

Passing an arraylist to a method

While studying for my upcoming exam I came across this question. (Question 1 as a comment in the code) public class List { public static void main(String[] args) { ArrayList<Song&...
0
votes
1answer
41 views

Is it possible to sort a list of objects in Java through a common field? [duplicate]

I have a list of objects on my software that i want to sort through a common field, example : List<Object> obj ID 1 Price 0.0 ID 1 Price 1.2 ID 1 Price 1.3 ID 2 Price 2.0 Can i sort the list ...
0
votes
3answers
47 views

Enhanced for-loop seems to be going through all elements at once. But is it supposed to or is my code wrong?

Sorry about title. I'm trying to write a program that replaces the elements from an array A with elements from an array B of the same size, while also removing those elements from array B. Nothing ...
0
votes
1answer
29 views

Adding multiple markers on Google Maps with ArrayList

I am calling API then adding JSON data into a arraylist, then calling the arraylist data and placing the Latitude and Longitude onto the map, placing multiple markers. I believe my problem is the ...
-2
votes
0answers
42 views

How to put parsed lines into an array? [on hold]

In the main class I have put these strings into an array that will be parse in another method public static void main(String[] args) { String s1 = "2019-05-10T06:00:00+00:00 pspapi-ctwbcp4a #Date:...
-1
votes
2answers
34 views

How to shift an element in a list through all the positions and print all the results? [on hold]

I have a list, say, a=[0,1,2,3]. How can I print an output that moves 0 through all the elements one by one and prints them? I have tried the list.pop() and list.rotate(), but they just do it once ...
0
votes
0answers
29 views

Firebase query does not work correctly when it depends on the ArrayList Size()

From every query, I'm fetching information of 1 user. Here are 3 queries. The last 2 queries depend on the list size that comes from the previous query. But every query results in fetching 1 user in ...
1
vote
3answers
52 views

index of the largest item in the ArrayList

Let's take this ArrayList for instance [1, 3, 8, 9, 5, 7, 9]. I am working on getting the index of the largest item in the list and if the list has this item more than once, each time return a ...
0
votes
1answer
31 views

I am reading from a file, the if loop or why loop is not picking up the first button “7” but getting all of the rest

I have put lots of output messages to help me to try to follow the code. Everything looks like it is working up until the first time it reads button "7". It immediately goes to button "8". ...
-2
votes
3answers
44 views

Do setOnItemClickListener in listView which is made by of Arrayadapter [on hold]

Please help me, I want to show other activity when clicked in "about us", "more from us" of listView, how can I do that? ArrayList<Word> words = new ArrayList<Word>(); words.add(...
0
votes
1answer
31 views

how to read data from arraylist that is inside linkedlist

I have an arraylist of year and value. this arraylist is place in a linkedlist as one of element in the linkedlist. linkedlist elements -> countrycode, indicatorName, indicatorCode and data (...
0
votes
0answers
55 views

ArrayList of arrayLists predicate method error

Am having an implementation of ArrayList of arrayLists and trying to write an Predicate implementation for the same. Please find my below code. Pojo class Menu.java public class Menu { private ...
-2
votes
1answer
39 views

Java static method with a parameter ArrayList<Integer> - add doesn't work [on hold]

I have the following problem. I have a piece of code: private static void(ArrayList<Integer>[] elements){ //do smth add.elements(new Integer(5)); } Can somebody explain me, why add method ...
-1
votes
1answer
30 views

how to perform addition on numbers that entered in listView? i tried this way it is not working

public class MainActivity extends AppCompatActivity { EditText actv; Button bt, total; ListView lt; String getInput; ArrayAdapter adapter; TextView tv; int num, sum =0; final ArrayList addArray =...
2
votes
3answers
53 views

List contains method returns false when using Math.sqrt() as a parameter

I am refreshing my knowledge in Java and working on an exercise from codewars. The problem is to compare two arrays if the elements are the "same". The meaning of "same" is that the elements in 'b' ...
0
votes
2answers
36 views

how to group 59 elements into one element in arraylist?

so, i have a program that read value and its year from a textfile that starts from 1960 till 2018. each indicator code have different values but the year stays the same, 1960-2018. i have successfully ...
1
vote
1answer
21 views

Java: How to get data from ArrayList<Data Type>

I'm trying to make an app that manages contacts. I'm having difficulty getting the data within those contacts. This is my ContactsManager class public class ContactsManager { private ArrayList<...
0
votes
1answer
35 views

Array Push Function not working correctly

problem is simple i am trying to push values in array but it's creating every time new one instead to add i tried many ways to do the same thing you can check code here what actually i am doing $(...
0
votes
1answer
20 views

Update Recylerview : notifyDataSetChanged() doesn't work with a ArrayList from SharedPreference

I have two buttons (Add contact) and (Clear All Contacts), each time I fill information about the contact (name, phone, picture) I save them using SharedPreference, so if I close the app and reopen it ...
-1
votes
2answers
32 views

How to make m by n matrix with all elements int x using ArrayList?

Making m by n matrix using ArrayList in Java. I'm trying to make a constructor with the function of making m by n matrix with all elements 'int x'. I've declared matrix ArrayList<ArrayList<...
0
votes
1answer
36 views

Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: java.util.ArrayList

I'm doing a library management project and when I register a member to the library is registers properly "the write method works fine." the Error message is "Exception in thread "AWT-EventQueue-0" ...
1
vote
1answer
26 views

How can i open new activity by clicking on banner which i had implemented using viewpager?

i have implemented an auto rotating banner with viewpager and handling images with arraylist but i want to open new activity on clicking to the banner which i had used i am not getting how to handle ...
0
votes
1answer
21 views

If statement that performs segue with UIPicker

I am building an app where at a certain question I am able to use a UIPicker to go back to go back to previous questions, however I either get an error or nothing happens when attempting to use the ...
-3
votes
0answers
33 views

Does this function rightly shuffle the first elements of a list into the whole list? [closed]

I would like to transform a partially shuffled list (the first elements are not shuffled) into a fully shuffled list, I came up with this method, but I'm not sure that it produces a balanced shuffle, ...
-4
votes
1answer
36 views

Merging two different data type of array list in to a single array list

I am trying to merge two different array list data-types, and obtain the output in combined form, for example merging the below two types, i have used for each and for loop private ...
0
votes
1answer
55 views

Data duplicates in Arraylist

I want to fill my ArrayList with data selected from my database but it duplicates all the rows i don't get it. Connection conn = DriverManager.getConnection(url, userid, password); ...
2
votes
6answers
85 views

How to find the smallest number that is common among the 3 arrays?

This is the question: Given 3 random arrays of integers, write a method to find the smallest number that is common among the 3 arrays. HINT: Sort first and just traverse first few elements until you ...
1
vote
6answers
63 views

How to convert number value into array with separate value at array where max value of index at list will be 1

Need some help. I have example value 4.8 (it's a value from rating 4.8/5) Now I need to convert it into array where array should be like this [1, 1, 1, 1, 0.8] What do I mean? It should take ...
-5
votes
0answers
51 views

How to explain this situation? What happened to the memory?

foreach(Object x in Arraylist) { if(x.a.b.equals("something")){ this.listView1.Items.RemoveAt(Arraylist.IndexOf(x)); this.listView1.Items.Insert(Arraylist.IndexOf(x), new ...
1
vote
4answers
48 views

Create list of an element of an Object from another list of Objects

The model: public class MyModel{ private int id; private String name; .... .... //getters and setters } I have a list of MyModel object: //First Object to be added to list ...
0
votes
3answers
28 views

Why does my jsonarray results storing only one record into array?

This is my volley task and I want to store response data to arraylist. I am getting the whole result in the console but in arraylist it is storing only first record private void loadJsonArray() { ...
-2
votes
0answers
12 views

How to Remove one object in List<Map<String,object>> in Java [duplicate]

I have one map list. It has some values. I want to remove one object in the list with values. [{district_id=37, District=Barabanki}] My list has this type of values. I want to remove one object in ...
-7
votes
0answers
42 views

Saving HashMap values of a specific key to ArrayList [closed]

I have an HashMap<String,String>. Is it possible to iterate, from the HashMap, the "values" that have the same "key" and save them in an ArrayList<String>?
1
vote
3answers
66 views

How can I add an information to an existing element in an arraylist?

have a question about this code. How can I add information to an existing element? For example in the beginning the machine asks the user to give a name. If I give the name "Harry" the machine will ...
2
votes
1answer
55 views

How to remove an item from an arrayList upon collision?

Trying to make a copy of the game Tank Trouble and I have no idea how to do collision detection with the bullets and the walls/ players. The bullets are generated when the mouse is pressed but I don't ...
0
votes
2answers
76 views

How to to hide josn object in recyclerview based on condition?

I Have one json array in array list i need show one object as count and one as text view, while going to filter the object i'm not able to find count view and display view, i search for hash map but ...