I want to write a method which finds the longest String (word). The output should be the longest word in case of two words with the same lenght the output should be: “More than one longest word”. I used ArrayList and almost had a solution, but something goes wrong. The case is that I have a problem when two words
Tag: arraylist
Storing Objects of multiple classes in an Array List, then accessing their attributes
I have class of (sub)Objects And a class of Objects The Objects hold the values height and width and an ArrayList of SubObjects. This works as intended, I do however want to store multiple types of SubObjects from different classes in these ArrayLists. After a bit of googling I changed the Objects class to This allows me, as I intended,
ArrayIndexOutOfBoundsException while getting values from hashmap in Java 17
I have a static HashMap<UUID, MyObject> ALL = new HashMap<>(); which is used in multi-threading. To reproduce the error, I made this code: But, after some seconds (around 10), I get this error with Java 16 and Java 17: With Java 8, I get this: To test, I remove synchronized key-word, then try again in Java 17 and I get
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 is Not reserved, depending on the input you enter in the menu. I am trying to correctly write a for loop for both ArrayList that contains if statements,
Im trying to delete elements of an arraylist via inputs but the program stops at the third input, I would like to know why it does that
Im trying to delete elements of an arraylist via inputs but the program stops at the third input, I would like to know why it does that. Scanner scan = new Scanner(System.in); } Answer There are a couple of problems with your program. The condition of for loop was not correct and some other minor issues. Here, is a better
How to send variable to method through an arraylist
I’m not very good at explaining things but can someone try to explain to me why my user input variables are not being sent to my methods in another class? This is my main class: } This is an example of one of my subclasses that I am trying to send the variables to. All the other ones are the
Remove an Object from an arraylist in a hashmap
I need your help, I created this two classes I need a method in Graph to delete an Arch from the ArrayList that I have in the hashmap. I tried like this in the class Graph: but when I tested it in my test main the result is that nothing changed in my ArrayList in the hashmap. someone can help
creating exploitable .csv file for java program
I’m both new to JAVA and .csv file so bear with me please! Here’s my problem, i have this word file : basically i have a theme (here Science) a difficulty level, a question number, a question, available answers and a right answer I would like to be able to create a .csv file that i could then exploint in
Create and find highest value in subarraylist
I have an Arraylist of the Cells from an Excel sheet. I want to create subarraylists of size 50 from the Arraylist of Cells I actually have, beginning from the index of 1590 and ending with size()-700. I want to get the highest number from every subarraylist and put it in the new Arraylist. in the new Arraylist there should
Is there a simpler way to remove “duplicate” objects from an array (objects with the same property)?
If, given an array of objects, such as: How can one remove any objects that don’t have a unique attributes, whilst leaving only one. This could be as simple as duplicate names, which would leave: Or more complex, such as jobs that start with the same letter, and the same age: So far, the best I’ve come up with is: