Skip to main content

All Questions

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 ...
user avatar
1 vote
1 answer
3k views

Implementing a printAnimals method

I am trying to implement a printAnimals() method that prints the ArrayList for dogs or prints the ArrayList for monkeys, or prints all animals whose training status is "in service" and whose ...
Gman12's user avatar
  • 71
0 votes
1 answer
2k views

C# accessing element of object from List<> using for loop instead of foreach

trying to brush up my foundation on C#. How do I print the value of objects from a List? I have a List and wants to print out the Name and Age to console. I can use foreach loop to print them out ...
bunnap's user avatar
  • 47
1 vote
2 answers
277 views

Retrieve value from int array inside objects ArrayList

i am experementing on ArrayList which contains different data types and an int array and I want to access a value from the array for example number 55. Can I directly access this array without using ...
E.Y.309's user avatar
  • 33
0 votes
4 answers
4k views

How to search for an Object in ArrayList?

I want search for an object in an arraylist using one of it attribute: String name. I have printed out Item Found here, and this works just fine. public static void searchItems() { // variable ...
mante's user avatar
  • 99
0 votes
1 answer
57 views

Adding multiple objects to ArrayList using loop, all objects get updated when one is changed

I have been using a for loop to create and add new Graph objects to an ArrayList for use elsewhere in my code, but when I print the list all of the Graph objects inside are identical. An edit to one ...
SRP's user avatar
  • 3
0 votes
1 answer
222 views

I cant access the arraylist attribute of my object in java

So I have three classes, Employee, Event, and Main. The purpose of my program is to create a event management system where the user enters the name of the event along with the names and ID's of ...
Gjison Giocf's user avatar
0 votes
1 answer
48 views

Values assigned to a Java List inside a for loop are replaced by same object(object at index 0) after the for loop ends [duplicate]

I am creating an Object inside a for loop and adding it to a list as illustrated in the code below. The values are distinct and different when logged inside the for loop how ever once the loop ends, ...
Nikhil Varma's user avatar
-5 votes
1 answer
57 views

Cannot identify Error reasoning - Related to ArrayList and FOR loops, how could I fix my code? [duplicate]

I am creating a very simple simple Bank Manager Class which handles a number of Bank Account objects - each object is created with a unique accountNumber, accName, etc., This is how a bank account is ...
Pepe's user avatar
  • 59
-5 votes
3 answers
473 views

How do I create ArrayList of Objects (string car model, int count, string percentage) in a loop?

So I need to create Object for example called Car containing - String car model - int count - String percentage After getting this data how do I put all Car Objects into for-loop of Objects to get ...
George Constanza's user avatar
-1 votes
1 answer
43 views

2-dimensional array not working

I have a 2 dimensional array gets a specific animal from a text file, but for some reason it's not working at all. I have checked for any errors but I get no errors just no output. It just keeps ...
ertyui's user avatar
  • 1
1 vote
1 answer
109 views

Why does my array contain the same elements?

Java beginner here. I'm trying to add Result objects from an ArrayList to an Array (to be sorted later). I know ArrayLists probably would work better but I'm required to use at least one array in this ...
Nathalie's user avatar
  • 113
0 votes
2 answers
224 views

How would I find the max value of objects in ArrayList in for-loop? -Java [closed]

So it seems that both my methods in my Persons class are giving me the wrong information. I have two methods called get totalSalary() and maxSalary() that go through ArrayList personList and calculate ...
EdtheGreat's user avatar
0 votes
4 answers
133 views

Scanning through ArrayList for Objects with same field

I have a simple class Creator: public class Creator { private String name; public Creator(String name) { this.name = name; } public String getName() { return name; ...
user avatar
-1 votes
3 answers
2k views

Java: NullPointerException on a Null Check? [duplicate]

I have read through some of the NullPointerException threads on here, and have formatted my code to use one of the simple checks I found, but I'm still getting a NullPointerException. Full Code: note ...
Bob's user avatar
  • 1,376

15 30 50 per page