I’m new at Java and I have a question. I have this array of objects: That contains this: I would like to know how can I filter this array by month and year. A first example would be filter the array by month 10 and year 2021. Any suggestion ? Answer You can use the Stream API to do it
Tag: arrays
The method countTrue(boolean[]) in the type GUI is not applicable for the arguments (boolean, boolean, boolean, boolean, boolean)
this is the error : “The method countTrue(boolean[]) in the type GUI is not applicable for the arguments (boolean, boolean, boolean, boolean, boolean)” , the error is in the last line , but i dont get why. Answer New array should be declared as below: int x = GUI.countTrue(new boolean[]{true, false, false, true, false}); OR you can use varargs and
How to merge two sorted array?
Question is ==> You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside
data type and calculate average in java
I am working on a java code that calculates the average of grades in an array for N of students and it is working fine when I enter grades like {3,4,3} but when I use numbers with decimals like {3.7,2.5,3.2} it starts giving me errors and I want to make a class of data type Students for example. Any help
how to prompt user to input array values and create a data type in java
I am working on a java code where it should prompt the user to input the grades of N amount of students and it should output the highest grade, My code is working well but I want to give the user ability to enter the content of the array and I want to create a data type called Student for
Creating user input for randomized 2D java array issue – OutOfBoundsException
Trying to create a 2D array that takes the users input for rows and columns. The numbers inside the array are then randomized from 0 to 100. I am getting the following error: Enter rows for the array: 3 Enter columns for the array: 2 Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 at test2.main(test2.java:17)
How would I add two int that are in the same array to each other and convert them into an int. In the Luhn Algorithm
I am trying to add two parts of an array together to go into an int value. I am using Luhn algorithm to figure out of a credit card is a valid credit card. We are only using 6 digit credit card’s just to make sure no one enter’s a real credit card number. The part I am confused on
How do i make use of groupingby in java
I have a movie list from a web service that i need to group using genres attribute from the data. My question is very similar to this groupby ngFor angular2 but in java instead. movie list from the web service looks like this here is what i’m trying to achieve but i cant seems to get it right i’ve tried
2d double array to image
I’m currently working on a simulation with continuous agents, which leave a pheromone trail on a 2d double array. The pheromone trails need to be on a 2d array because of a diffusion with a mean filter that needs to be performed. Ultimately, I need to visualise the agents and the pheromone trails, by transforming the double array directly into
(Java) How can I make a loop that will assign random names I’ve generated from an array to multiple strings?
Relatively new to Java, looking for a solution to a crucial part of a game I’m making for a class. The idea is to make a very simple stock market simulation game, but the problem is related to creating made-up company names. I have three arrays for the first, middle, and last names of companies. I’m trying to make some