We create a new list: List<Integer> result = new ArrayList<Integer>(); Finally we convert it to int array and return this array: return result.stream().mapToInt(i -> i).toArray();
Comparator Interface in Java
Comparator interface is used to order the objects of user-defined classes. A comparator object is capable of comparing two objects of two different classes. Method 1: One obvious approach is to write our own sort() function using one of the standard algorithms. This solution requires rewriting the whole sorting code for different criterion like Roll …
Conversion between String and Integer in java
From String to Integer Integer.parseInt(my_string); From Integer to String Integer.toString(my_integer);
Difference between == and .equals() method in Java
In general both equals() and “==” operator in Java are used to compare objects to check equality but here are some of the differences between the two: Main difference between .equals() method and == operator is that one is method and other is operator. We can use == operators for reference comparison (address comparison) and …
Continue reading “Difference between == and .equals() method in Java”
Sorting a HashMap according to keys in Java
Using TreeMap // Java Code to sort Map by key value import java.util.*; class sortmapKey { // This map stores unsorted values static Map<String, Integer> map = new HashMap<>(); // Function to sort map by Key public static void sortbykey() { // TreeMap to store values of HashMap TreeMap<String, Integer> sorted = new TreeMap<>(); // …
Continue reading “Sorting a HashMap according to keys in Java”
Java Iterate through a HashMap Example
Using for each to iterate through a HashMap Using for each to iterate through a HashMap import java.util.HashMap; import java.util.Map; public class IterateHashMap { public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println(entry.getKey() + " = " + entry.getValue()); …
Notes on reviewing Dynamic Programming
I believe the topic of Dynamic Programming is a hard part of Algorithm. For this reason, I plan to read the related content in Introduction To Algorithm first and take some notes before I start solving problems in LeetCode. What is Dynamic Programming Dynamic programming typically applies to optimization problems in which we make a …
Creating an EC2 Instance on AWS
What is EC2 and AWS? Amazon Web Services (AWS) is a cloud platform that offers many powerful internet services. Their most popular service is Elastic Compute (EC2), a platform which allows you to create virtual machines in the cloud to run applications on. The hardware behind the VMs (network, storage, CPU, RAM) is all handled …
How to use Docker?
What is Docker? Docker is a platform that allows one to package an application with all of its dependencies and surrounding environment in an isolated container. This is useful because the next time you want to deploy your application somewhere else, for development or production, you can simply pull down that container rather than setting …
Some notes on CRUD application – Node.js, Express.js & MongoDB
CRUD – READ In Express, we handle a GET request with the get method: app.get(endpoint, callback) endpoint is the requested endpoint. It’s the value that comes after your domain name. Here are some examples: When you visit localhost:3000, you’re actually visiting localhost:3000/. In this case, browsers requested for /. You’re reading this article on https://zellwk.com/blog/crud-express-mongodb/. …
Continue reading “Some notes on CRUD application – Node.js, Express.js & MongoDB”