All Questions
1,092
questions
1
vote
3
answers
77
views
Can an object belong to both an array and arraylist simultaneously in Java?
I am struggling to write a code sample where an object can belong to an array and arraylist simultaneously and where modifying in arraylist or the array changes the object? See example where I was ...
-1
votes
1
answer
44
views
Why is the second instantiation of the Player object rewriting the first in this Java program?
I am attempting to write a program that will allow a user to input four characteristics of a "Player" object and add that object to an array list of other Player objects. However, it seems ...
0
votes
1
answer
61
views
Mooc.fi Java 1 -Part07_07 Recipes
(Apologies for the formatting this is my first post)
I am looking at teaching myself Java through mooc.fi Java from the university of Helsinki,
I have been attempting this problem for 4 days straight ...
-1
votes
2
answers
77
views
Adding Coin Objects to Wallet Objects
I want to create a program where you're able to add and remove coins to a wallet, as well as show the total amount of money in the wallet. All through OOP. I've created a while loop where there are ...
1
vote
2
answers
160
views
C# Add List class to new List class without looping
I have a list of users returned in a class
My Class: List
public class EmployeeList
{
public int Emp_No { get; set; }
public string Sys_Prefix { get; set; }
public short Company_No { get; ...
0
votes
4
answers
109
views
Do I need unique names for all my objects in a list?
I am a first year Comp Sci student. For part of an assignmentI have for my Java class. I need to create a deck class that is an ArrayList containing Card objects.
Here is an example of a card object I ...
1
vote
0
answers
17
views
Can't add elements of another class (same package, public) to Array list. I was doing it before(im sure about it, can send code) but now i cant
I can create new Task object, ArrayList of the Task, but when I'm trying to add (early created or to create it when adding) Task object to List, it says that "Cannot access todo.Task."
I was ...
-1
votes
1
answer
76
views
How can i make a container of objects and how can i use it in other file
I basicly have an array list in my main class
public static void main(String[] args) {
List escenariosLi = new ArrayList<Escenario>();
String a = "";
escenariosLi.add(0,new ...
2
votes
3
answers
65
views
Split an List of objects based caseNumber into a new List of objects
I have an List of Messages objects. My message object consist of sender and CaseNumber. A SQL query is pulls all the messages into a list. In this list I have multiple of the same CaseNumber.
What ...
-1
votes
1
answer
57
views
How to add objects to list without having array brackets
I have a for loop in which I add some attributes to the object and at the end I need to have a string (to pass it as a query parameter)
I need
{"items":[{"itemsCode":"item1&...
0
votes
0
answers
25
views
Serialization and deserialization a list
I'm trying to write ArrayList to a file, and then read a random string from the ArrayList.
In the code, I'm trying to output at least the entire ArrayList from the file (in order to select a random ...
0
votes
5
answers
126
views
How to print a name by a given ID
var people = [
{name: 'John', id: [34, 44, 77]},
{name: 'Jose', id: [43, 54, 65]},
{name: 'Hanna', id: [56, 34, 98]}
];
var peopleFinder = people.filter(function(b){
return b.id === ...
0
votes
4
answers
550
views
Difference between Array and ArrayList<> in Java in terms of memory allocation?
I came accross an article which had a question-
Contiguous memory locations are usually used for storing actual values in an array but not in ArrayList. Explain.
https://www.geeksforgeeks.org/java-...
0
votes
1
answer
18
views
Trying to Compute the differences in two different ArrayLists of Objects with Instance Fields of Type Integer[JAVA]
package pckg;
import java.util.ArrayList;
import java.util.HashMap;
public class Tester
{
public static void main(String[] args)
{
ArrayList<TesterObj> my_first_objects = new ...
1
vote
1
answer
65
views
Flutter: How do I iterate a nullable table and add each row object to my object list
Problem: The method 'query' can't be unconditionally invoked because the receiver can be 'null'.
1 - I already checked that the _database is not null. How do I get around this?
2 - I'm not sure how to ...
-2
votes
2
answers
99
views
How to parse an objects with array index to object array with key value pairs
Convert this object Students object to one Students array
{"SubmitBy":"SK", "Students[0].name":"Jhon", "Students[0].age":"15", "...
-2
votes
1
answer
2k
views
How to display a list of objects as a JList in java swing?
We are asked to build a system in Java Swing no drag and drop and I cannot understand how to display a list of objects in a JList.
I have a GUI class that creates a JFrame, JPanel, and an empty JList ...
0
votes
3
answers
744
views
How to get data from List<Object[]> using java 8
Trying to get a data from DB using JPA. My Data format was like [[John,Wick,New York],[Walter,White,New Mexico]]
And am using below code the get the data from List<Object[]> and with iteration ...
0
votes
1
answer
77
views
Referencing an interface from ArrayList
I am having trouble understanding ((Edible)objects[i]).howToEat() at line 7 in the java code example given below. Edible is an interface which contains abstract method howToEat() and I understand that ...
2
votes
3
answers
204
views
Group an array of objects based on multi keys in Javascript?
I would like to share with you an existence problem
I have array as follows
const data = [
{
"countries": ["France", "USA", "Canada"],
"city": &...
-1
votes
2
answers
76
views
Java - from Array to linked ArrayList why it doesn't affect all int values?
I am studing Java, i have simple Array linked to ArrayList, it is fixed size i can change values inside array or list without change length.
So i tried to change all elements of the Array to see ...
0
votes
1
answer
38
views
how to return numbers by column from objects that have array list attribute
I have a class where I am creating different "Processes", an attribute of this class is an linked list of Integers. I have created different class objects and to make it easy to loop through ...
0
votes
2
answers
317
views
Java.lang.NumberFormatException when trying to read in a file, so I can use the data with my objects
I keep getting this error when I'm trying to read in a file and add the data to my objects. Can someone please help me? Here is the error:
Exception in thread "main" java.lang....
-1
votes
1
answer
24
views
I'm doing an assignment for my class where I need to create the functions below for a Path. I'm having trouble on the functions, am I overthinking it?
import java.awt.Point;
import java.util.ArrayList;
import java.util.Scanner;
public class Path
{
ArrayList<Point> pointOne;
ArrayList<Point> pointTwo;
public Path() {
...
0
votes
1
answer
53
views
JAVA Attribute of ArrayList<Object> not returning values
Class Hospital
package app;
import java.util.ArrayList;
import app.Department;
public class Hospital {
String hospitalId;
String hospitalName;
int departmentCount;
ArrayList<...
0
votes
2
answers
164
views
How to create an object from a file?
I've a file with a line that looks like this "Room,home,You are in your home"
I wanna read the file and then create an object (I have created a class called Room), what I wanna do now is ...
0
votes
2
answers
28
views
How to join the objects that have the name in common and do the sum of the values of the key value1 and value2. Javascript
I have an array with the following objects:
const arrayData = [
{name: 'John', car:'BMW', value1: 500, value2: 350},
{name: 'Paul', car: 'AUDI', value1: 290, value2: 200},
{name: 'John', car:'BMW', ...
1
vote
2
answers
63
views
Javscript/TypeScript: Find the key and append value as an array
I have an object which is like
[{
Date: 01/11/2022,
Questionnaire: [
{Title: 'Rating', Ans: '5' },
{Title: 'Comment', Ans: 'Awesome' }
]
},
{
Date: 01/11/2022,
Questionnaire: [
...
0
votes
2
answers
447
views
How do I return a specific object from an ArrayList?
So I'm trying to implement a method in a Grid class that returns the tile (which is an instance of the tile class) specified by two coordinates the user inputs. But I have no idea how to go about ...
-1
votes
1
answer
46
views
deleting duplicate objects from an arraylist
I have an array list consisting of objects defined in the class Result(date, name, grade). I have managed to sort the dataset. However I want there to be no duplicates, only the object with that has ...
0
votes
1
answer
66
views
Counting the presence of a key in an object array; key won't be in every element
I have an arraylist of log entries containing the following:
[System.Collections.ArrayList]$aLog = @()
$aLog.Add([pscustomobject]@{status='200';desc='ok'})
$aLog.Add([pscustomobject]@{status='404';...
-2
votes
1
answer
74
views
Combining array lists containing different objects in Java
im working on a small game in Java. I have an abstract class SuperHero, and the classes WaterHero and LandHero that extends from Superhero. How do I combine the two objects allHeroes and allHeroes2 in ...
0
votes
1
answer
265
views
How to wrap object in array in java?
I'm making a code to send data to the payment gateway. I am a beginner in using java. I'm having a bit of trouble working with objects in an array in the item_details parameter. I've made the code as ...
0
votes
2
answers
110
views
Java: Print elements of User defined Classes using ArrayList [duplicate]
When I try to run the code I don't get 101,102,103 as output rather I get memory addresses of each value, I want to print the values 101,102,103 using "user defined class" pt_5_Employee as ...
1
vote
1
answer
45
views
Create new Object from a complex array of objects using Javascript
I have an array of objects and I want to push only the values of each object inside the array to a new object as a key value pair using Javascript.
eg:
const prices = [
{ ticker: 'msft', price: 14.3 ...
0
votes
1
answer
29
views
C# fails when adding ArrayList to Existing Object
Working in Visual Studio 2022 on an ASP.NET web app,
I have an object named tractObject with three items. The third item is an ArrayList that will hold a list of objects named standObject.
public ...
0
votes
0
answers
20
views
Trying to add an Object to an arrayList specified elsewhere
Whilst trying to make a class which I can use to add any object to an ArrayList from outside it I ran in to this problem:
public class AddToArrayList
{
public ArrayList stack;
...
-1
votes
2
answers
98
views
Cast object to int[]
I have a array (with type of Object) which I'm extracting from a System.Collections.ArrayList. And I'm now trying to cast this object to a int[] so i can use it to compare it with another int[].
Note: ...
0
votes
1
answer
100
views
Do-while loop ends program before while statement is met
Right now, I'm writing a program that will allow a user to create an infinite number of exercise objects, and will only stop when the user input is equal to certain a value. Below is the relevant code:...
0
votes
0
answers
17
views
I am trying to print out all objects from the array list question below but when ever I do it prints out a weird code? [duplicate]
public class Question{
private String question;
private String[] answers;
public int answerPosition;
public Question(String question, int size){
this.question = question;
...
0
votes
2
answers
1k
views
How can I store objects from another class in an ArrayList from a different class?
I am quite new to programming. I am creating a project where in class Countries there is data in the form of objects which contain the name of the country and the country's dialing code. There is ...
-1
votes
2
answers
156
views
How to remove object from an arraylist
its gonna seem complicated but I want to make a function that removes an object from the ArrayList of an object that is in another ArrayList
let me simplify it, there is a class with objects (students)...
2
votes
2
answers
857
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
2
answers
66
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 ...
0
votes
2
answers
94
views
How do i delete an object in an array which has a same name as another object in that same array?
I'm coding a simple fun project in Java, creating a loop which creates an object in an arraylist with the name+Random(1-60) (ex. Dog2, Dog6) 59 times.
And this loop, will check if an object it just ...
0
votes
0
answers
121
views
indexof returns negative 1 only
so I tried to find a value in an ArrayList and it always returns -1 even though I entered the value that does exist in the list.
I'm not sure maybe it's because I read them from a file?
public class ...
-3
votes
1
answer
102
views
When trying to overwrite a equals method in Java, it won't compare the values only the object itself?
In this exercise, I need to create a equals() method for a Drink class. Two drinks are the same if they have the same name and same size. I am receiving false from testing the method, even though I'm ...
0
votes
1
answer
266
views
Local Variable Memory Consumption
Which approach is better to declare local variable in terms of memory consumption?
public List<ResponseObject> mockMethod(RequestObject obj) {
List<ResponseObject> response = new ...
0
votes
3
answers
77
views
An Easier Way to Detect Differences Between Objects? (Java)
For instance, I have an arraylist called StudentListA and StudentListB that contains many students.
StudentListA = {Student 1, Student 2, Student 3....}
StudentListB = {Student A, Student B, Student C....
-3
votes
1
answer
366
views
How can I save only some elements of a List in an ArrayList? [closed]
I tried to do this, but the add in the line arrayList.add give me an error
List <Recipes.Results> list;
ArrayList <Recipes.Results> arrayList;
arrayList = new ArrayList&...