How-to articles, tricks, and solutions about JAVA
Basic Java Float and Integer multiplication casting
To perform a multiplication between a float and an integer in Java, you can simply use the * operator as you would with any other numeric data types. The result of the multiplication will be a float, even if one of the operands is an integer.
Best way to convert an ArrayList to a string
To convert an ArrayList to a string in Java, you can use the join method of the String class, which allows you to join the elements of the ArrayList into a single string. Here's an example of how you might do this:
Best way to create enum of strings?
The best way to create an enum of strings in Java is to define the enum type with a String field, and then specify the possible values for the enum as string literals.
Break or return from Java 8 stream forEach?
To break or return from a Java 8 Stream.forEach() operation, you can use the break or return statements as you would normally do in a loop.
C# Java HashMap equivalent
In Java, the HashMap class is the equivalent of the Dictionary class in C#. It is a map data structure that stores (key, value) pairs and provides fast lookup and insertion of elements.
C++ performance vs. Java/C#
C++ is generally considered to be a faster and more performant language than Java or C#.
Calculate date/time difference in java
To calculate the difference between two dates in Java, you can use the java.time package (part of Java 8 and later) or the java.util.Calendar class (part of the older java.util package).
Calculating days between two dates with Java
To calculate the number of days between two dates in Java, you can use the Period class from the java.time package introduced in Java 8.