Skip to content

Tag: java

How to correctly use the Threads

I have the following task : Create Class called: ElementsProvider(int n, List elements) that will provide N random elements into given list. Elements Provider will be an thread. Try create 4 instances, each of this instance will add 1000 random elements into the list. start all instances at once and wait unti…

reverse a string using recursion with java

I am trying to write a recursion to reverse a String.This is my approach. I dont get why when it reaches the base case, where my a is already empty but I am still able to print out the reversed string. Answer you are not implementing any recursion, you just replaced two halves of a string.

Read String json array and convert to List object

I have the below json string that comes from the db. I have to read the json and return the equivalent java class. Json String: Items class Here I am trying to read the above json string array using ObjectMapper.readValue() method and convert it to List. I have tried with the below code and getting the error …

Clock thread in Java

I have been studying about Java Thread recently. I created this simple clock that will display how many seconds have passed. It looked like this Here is the code for the application above (including 2 classes: Main and ClockPanel) The problem is: if i remove the line System.out.println() (as i commented in th…