All Questions
1,068 questions
0
votes
1
answer
61
views
how to efficiently check common elements of two lists of different types ( class A and class B) and make a resultant list of type A for all matches
I have a list of class A with 1000 elements that has all unique ids. There is some other Class B , which also has a unique id parameter and this B is a json property of Class A.
the relation is like :
...
0
votes
1
answer
31
views
compilation process in some java question about relate to 2d arrays
public static boolean ContainedArr(boolean[][] photo, boolean[][] sub) { //find if sub is sub array in photo
if (sub.length>photo.length ||sub[0].length>photo[0].length) { //sub bigger ...
0
votes
1
answer
159
views
Java code recursive and iterative methods have different answers
I'm starting to lose hope and sanity...
I'm learning Java code and trying to write a program for choosing hobby, but it must be done by two methods and mine give different numbers... I don't know ...
-1
votes
1
answer
60
views
How to compare two maps and bring the results in new map
I have one Map
Map<Long, List<Set<Long>>> map1; Example: Map<City_Id, List<Set<Subtier_Cities_ids>>>
There is Another Map `
Map<Long, Set<Long>> map2; ...
0
votes
1
answer
64
views
Read nested list with other attributes in Java streams
I have a list of object for example Person in turn have couple of lists with few generic attributes like below
List<Address> address1 = List.of("1","2","5","6&...
-1
votes
1
answer
111
views
How to efficiently search an element in a TreeSet without using contains?
I'm quite new to Java and its libraries so its possible this question comes as a dumb or obvious one.
Assuming I have a class like this:
public class Person implements Comparable<Person>
{
...
0
votes
1
answer
164
views
Java Foreach Loop through Hashmap Throwing NPE -- What might the problem here be?
As part of a project, I've been tasked with creating a method that outputs a List of the most commonly occurring Strings in a given input List. The assignment specifies that this must be done by ...
0
votes
1
answer
100
views
How to iterate backwards with a custom iterator in Java using permutations
I am trying to create a a class of Permutation that extends Iterator and adds two methods: previous() and hasPrevious().
It must offer a constructor with one argument: a string containing the ordered ...
0
votes
1
answer
142
views
Perform value validation with lambda expression
I need to perform validation that specific String is appearing in DevTools traffic (Selenium 4 / Java)
I saw several examples like this:
devTools.addListener(Network.responseReceived(), entry -> {
...
4
votes
2
answers
280
views
How can I learn to convert recursive solution to iterative solution while preserving the space complexity?
I am trying to solve a easy binary tree question to convert the existing binary tree to a sum tree.
The recursive solution for this is :
class Solution{
public void toSumTree(Node root){
...
1
vote
0
answers
56
views
Why does the recursive version run slower?
I wrote two versions of a helper function for a leetcode problem. I was surprised to see that the iterative version runs over twice as fast, despite being essentially the same code.
I was assuming ...
0
votes
0
answers
50
views
Map Object properties from another list
I have two lists below:
List students; where Student class is as below:
public class Student {
private int id;
private int addressId;
private String name;
private String address;
}
public ...
1
vote
3
answers
664
views
Balanced BST From a Sorted Array - Iterative Approach
I want to create a balanced BST from a sorted array iteratively. I understand how to create this BST recursively, but how would you go about doing this iteratively? assuming a Node in the tree has ...
0
votes
1
answer
57
views
Java use global variable reset in iteration
I have the code work with iteration in a single thread enviorment:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java....
0
votes
3
answers
263
views
How to put asterisks on for looping
System.out.println("Enter your number");
int num = scanner.nextInt();
int count = 1;
for(int i = 1; i <= num; i++) {
for(int j = 1; j <= 1; j++) {
for(int k ...