Questions tagged [arraylist]

1

votes
5

answer
75

Views

How to calculate average from an arraylist only "calculating the positive numbers while ignoring the negatives)?

I'm trying to calculate a positive average from an arraylist. It takes values from an arraylist but calculates only 'positive' numbers, While testing Integer[] array = new Integer[]{3, 2, -4, -7}; ArrayList arrayList = new ArrayList(Arrays.asList(array)); System.out.printf(averagePositive(arrayList...
dipte
1

votes
3

answer
29

Views

How can I delete special characters inside a nested array?

So let's say I have an array like this, what would be the most effiecient way to go through the array and erase all the '$' signs? I have tried many different approaches but none of them seem to work properly, any thoughts? const myArray = [ ['$','H','e','$','$','l'], ['l','$','o','$','W','o'], ['r'...
Diogo Sequeira
1

votes
1

answer
61

Views

Checking if an ArrayList exists in a map

My football team has 5 different teams and I am trying to make a program to keep a track of which players are registered with each team. I want to be able to add a new player but first the program checks if that player is already registered. I would also be able to add new teams in the future and ag...
Joe Pasquale
1

votes
3

answer
42

Views

Trying to save a class (in a list) to a file

I am trying to create a program where I can store NPCs in a game with certain attributes. Such as: Faction, personality, interests/hobbies. To achieve this, I have created an NPC class. class NPC: #name, faction, position/job, character, interests, other def __init__ (self, name, faction, pos, char,...
DustyHalo
0

votes
1

answer
34

Views

ArrayList with more 10 items saved not ordered to DB

I receive List dtos with 14 MyDto and try to save it to the database. I receive List loop dtos and on each step: 2.1 -> map MyDto to MyEntity 2.2) -> save and flush MyEntity to DB I expect 14 rows in DB, saved in the order in which I saved. For example: row0 row1 row2 row3 row4 row5 row6 row7 row8...
ip696
-1

votes
1

answer
19

Views

Why is my code not able to print stuff from the arraylist?

So I am working on a fitness app that takes in user information and outputs the number of calories they burn plus the meal plan they should follow based on their BMI. Well, so far I had no troubles and I saved all the info about what kind of foods to eat based on the meal plan in an ArrayList. Howev...
Needyboy
1

votes
2

answer
5.1k

Views

Index out of range exception while inserting elements into a list

I keep getting the following error: 'Index was out of range. Must be non-negative and less than the size of the collection', while executing the following code: try { string connectionstring = 'server=localhost;user id=root;database=itemdb;password=root'; MySqlConnection conn = new MySqlConnection(c...
Ruchir Sharma
0

votes
1

answer
11

Views

Silverstripe 3 list all templates (.ss - files) in a specific folder

Is there a ready made function in Silverstripe 3 to get all templates living in a specific folder to have them in an Arraylist? if not, anybody done that before? my goal is to choose the template from a dropdown or radio-button-set. or should i do it with something like... $files = glob('/path/to/di...
Sepp Hofer
1

votes
2

answer
531

Views

How to create a map of character and dynamic ArrayList in Java

I want to create a hashmap defined as HashMap. What I am trying to do is to read a set of strings which I am reading into a list. From this list I want to generate this hashmap. So if strings are something like this Andy,Aman,Rocky,Ravi,Nick etc. Map should be like A->[Andy,Aman] R->[Rocky,Ravi] N->...
1

votes
2

answer
3.9k

Views

Compare the ArrayList values and HashMap values

I have a small query with respect to the comparison of ArrayList value with the HashMap value and extract the key value if they are equal. I am reading two files and storing them in ArrayList and HashMap respectively. I have to compare these values and extract the key from HashMap. For example: Arra...
-3

votes
0

answer
14

Views

List comparison and merging in java

I have 2 lists with complex objects such as they have a heirarchy: products->functions->resources. Products has product code and list of functions. function has functioncode and list of resources. Resource has array of string. I have two lists both os which have same product code and the embedded ob...
Mikelear er
1

votes
4

answer
90

Views

android how to find similar string in an arraylist [closed]

I have a list and show it in a recycler view.but I want use a search view and search all names that is in list.I want when I search 'ab' every names that contain 'ab' display in my recyclerview.I can do this with query and use 'like' but I dont know how can do it without query and search in a string...
john
1

votes
1

answer
389

Views

Angular 7: Access list element in an array

I'm trying to get one component of a list. The list is in an array. How do I get one specific component of the list? In this case I'm trying to get the 'source' element of hierarchialGraph.links. Code: Typescript of the array (just a snippet): showGraph() { this.hierarchialGraph.nodes = [ { id: '1',...
Michael
1

votes
2

answer
83

Views

How to Convert String to List<String> in Java Without using Jackson Api

I need to convert String to List in Java without using Jackson Api. My String is like String abc = '[\'A\',\'B\',\'C\']'; I want it to convert into List. I already have net.sf.json and org.json.simple imported. I can not use Jackson API but is there any other way to do this instead using split?
dPatel1582
1

votes
2

answer
46

Views

Querying data from Firestore to Arraylist but got nothing?

I have trouble adding data in ArrayList. I tried to add data in array list but got nothing Here's my code public class fmMain extends Fragment { private ArrayList posList = new ArrayList(); public fmMain() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater in...
Supagon Srisawas
1

votes
2

answer
56

Views

ArrayList: How to arraylist.set when you have multiple setters

I currently have 2 classes. My bot: public class Bot { private int X; private int Y; private int degress; public int getX() { return X; } public int getY() { return Y; } public int getDegress() { return degress; } public void setX(int X) { this.X = X; } public void setY(int Y) { this.Y = Y; } } and...
Kappa Coder
1

votes
3

answer
83

Views

How to put async method in a list and invoke them iteratively?

Recently I want to implement a health check for a list of service calls. They are all async task (e.g. Task method_name(...) I would like to put all of them into a list. I followed the answer of this post: Storing a list of methods in C# However, they are async methods. I put it like this: a collec...
Terence
1

votes
1

answer
76

Views

Is null when new ArrayList

I had a error when watching online product, code is like this, but an NullPointedException bother me, this error only appear once, and I can not reappear it. I can not understand why ArrayList is [null, 1]: public void test4() { class PlayerTask { List targetValueList; List getTargetValueList() { i...
doubleevil
1

votes
3

answer
49

Views

How to Determine Frequency of String Array List Elements Using Classes in Java

For a Java code, I have a class Called Animal where I have variables + their getters and setters such as name and age. The main method (in the Launcher class) allows the user to 'Drop Off' an animal using the addAnimal method and allows the user to 'Pick Up' an animal using the removeAnimal method....
Yashvi Shah
1

votes
1

answer
114

Views

Is ArrayList.forEach() a mutative operation?

I have a HashMap groups which maps to ArrayList objects for its values. I wanted to re-assign the values given they meet a particular condition (i.e. in this case, they are present in another list) and came across the forEach method. Here's how I implemented it. I could not find any documentation as...
Garikai
1

votes
4

answer
61

Views

Java - limit ArrayList to only 250 digits

I have a project which uses an ArrayList to store timestamps. With this ArrayList, I calculate the average parking time for each car within a garage. If I run my project for let's say 5 minutes, that specific ArrayList has already been loaded with about 10.000 different timestamps. Therefore I want...
Rainier Laan
1

votes
6

answer
113

Views

Convert ArrayList<String> to byte[]

I want to be able to convert an ArrayList that stores the contents of a file read from a BufferedReader, then convert the contents into a byte[] to allow it to be encrypted using Java's Cipher class. I have tried using .getBytes() but it's not working since I think I need to convert the ArrayList f...
munjyong
1

votes
2

answer
49

Views

acces to a subclass variable in arrayList

I want to access the method getDimensioni of an element of a subclass of Campo called Calcio. Here's the code where I want to do it: ArrayList campiprenotati = new ArrayList(); public void prenotazioniCC7(){ for (Calcio calcio : campiprenotati) { if('7'.equals(calcio.getDimensioni())) { System.out....
Dario Birtone
1

votes
1

answer
56

Views

Java 8 nested list as singleton list in parent

public class Parent { String name; List children; } public class Child { String childName; } I have these 2 classes by which my data set becomes as below: List parents = new ArrayList(); List _child1 = new ArrayList(); _child1.add(new B('p1c1')); _child1.add(new B('p1c2')); _child1.add(new B('p1c3')...
gaurav arora
1

votes
3

answer
46

Views

How to convert Arraylist into 2D double[][] array

I have an ArrayList which has objects of Coords which are x and y: ArrayList positionsArrayList = new ArrayList(values); class Coords { int x; int y; public boolean equals(Object o) { Coords c = (Coords) o; return c.x == x && c.y == y; } public Coords(int x, int y) { super(); this.x = x; this.y = y;...
Keyur Kariya
1

votes
2

answer
69

Views

How to filter null values in ArrayList

I have a very big code. I faced an issue where at very starting of code, null gets inserted inside arraylist custlist i.e custlist looks like [null]. And after many lines of code, I had my code changes where I was building up Predicate using custlist as shown below: CriteriaBuilder cb = entityManag...
ASharma7
1

votes
2

answer
45

Views

ArrayList of abstract and nested classes conflict

I have an adapter: class PhotoAdapter : RecyclerView.Adapter() { fun addItems(list: ArrayList) { val position = items.size items.addAll(list) notifyItemRangeInserted(position, list.size) } abstract class AbstractItem( open val id: Int ) class PhotoItem( override val id: Int, val url: String? ) : Abs...
CoolMind
1

votes
3

answer
13.5k

Views

How to Convert an ArrayList to string C#

ArrayList arr = new ArrayList(); string abc = What should I do to convert arraylist to a string such as abc = arr;Updated QuestOther consideration from which i can complete my work is concatination of string(need help in that manner ). suppose i have a string s='abcdefghi..'by applying foreach loop...
RollerCosta
1

votes
2

answer
35

Views

About ArrayList and Generic Type [duplicate]

This question already has an answer here: What is the point of the diamond operator in Java 7? 7 answers What is a raw type and why shouldn't we use it? 15 answers 1. First: What is the difference between ArrayList myList = new ArrayList(); ArrayList myList = new ArrayList(); 2. Second: If i decla...
1

votes
1

answer
48

Views

New to classes and my class doesn't work. Why doesn't it?

In my program, I want to have triangles that spin and follow your mouse position. I had it working but it was ugly because I didn't use any classes (I'm new) and just pasted the triangle over and changed the variables. This is the class I came up with. class Enemy { float x = random(-width, 0); floa...
Ethan Graney
1

votes
1

answer
147

Views

How to show specific data in spinner with Firebase?

My data is being retrieved, but I only want to display the names in my spinner like URL_xxx_NB or URL_xxx_FR, because I'm storing different URLs when people use the app in another language, and I need to retrieve only the names and when I put datasnapshot.getvalue() it brings me the whole thing, nam...
Gastón Saillén
1

votes
0

answer
73

Views

Java: Efficient way to search for multiple objects in a large list

Im working on a java code to read and retreive specific data from a XML file and then upload it to a Database, the data I need to retreive is determined by a CSV that has a name and the complete path of the node within the XML file, aftear reading the CSV file Im storing all the paths in a List of S...
Omega Kewt
1

votes
2

answer
39

Views

Generating a table in JavaScript for Year, Month, Day

$scope.generateTable = function(year) { // use year and loop through each month to build an array dynamically this.year = []; this.month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; // make an array for that starts wit...
Ar8itrator
1

votes
1

answer
73

Views

Object as a key value in HashMap and using in jsp

@Entity @Table (name = 'lectureHall_details') public class LectureHall { @Id @GeneratedValue(strategy = GenerationType.IDENTITY ) private int id; private String Name; private String code; private String description; private int capacity; ....... } This is how my LectureHall class look like. @Entity...
1

votes
1

answer
98

Views

Java changed element in an Arraylist - need to keep previous & modify the rest

My program is a train schedule that shows cities with their arrival and departure times. In the program, the 'Delay' input prompts you to type the city name and number of minutes to add a delay in minutes to that city's arrival time. This information is all stored in a ArrayList Here is a link to my...
user9265540
1

votes
0

answer
38

Views

How to clear an object of list after it gets processed once with iterator

I have one method which is writing is processing csv file as below: public void processFile(Mapper mapper) { List outputDataList = new ArrayList(); Iterator iter = this.addressLists.iterator(); while (iter.hasNext()) { List listOfAddress = iter.next(); for (AddressDto address : listOfAddress) { this...
user9193174
1

votes
0

answer
113

Views

JSTL-Iterate in HashMap<String,Object> from JSP

I have a map HashMap were define on the nex way: HashMap issue = projectM.loadIssue(id_tarea); where the method 'loadIssue' call a store procedure from mysql. This procedure give back a list, then I convert the Hashmap in ArrayList> to iterate it in JSP. Now, I have the next line in my code: request...
Angel Mauricio
1

votes
0

answer
138

Views

How to sort an ArrayList based on another ArrayList order

So I have 3 different ArrayList`s which I need to sort to update my RecyclerView. final ArrayList Coin = tinydb.getListString('Coin'); final ArrayList Day = tinydb.getListDouble('Day'); final ArrayList Price = tinydb.getListDouble('Price'); I sort my Price list like this: Collections.sort(Price...
1

votes
1

answer
16

Views

List-View/-Adapter doesn'ts list data

I have a (probably small) Problem. My ListView doesn't list the Data I successfully inserted. My ListView is in my notes_layout and is declared as lv_notes in my NotesActivity . The Data it shall take is from my created Database db . The Data are getting inserted in an Other layout. : public class...
Get-Sly
1

votes
2

answer
127

Views

Separate data and store in ArrayList?

I am trying to separate a set of data. I need to store each data into a variable then create an object and put them in an ArrayList. The dataset is in this format lastName, firstName ID num_courses course1_name grade units course2_name grade units .... I have done this so far but I'm having troubl...
jCheon

View additional questions