We love to work with arrays because they are simple yet very powerful data structure in Java Language. It is also very intuitive and easy to use. If our needs does not require too much dynamic sizes, then arrays are just fine. But the first problem we encounter in working with arrays is how to fill it with initial values. Specially if the size of an array is created through a variable - meaning variable size that we don't know initially. And say we need to initialize the entire thing with a specific value, or only a portion of the array. The Arrays.fill() method is a good fit for this need. In this post we try to explore how to use Java Arrays.fill() method in different scenarios.
Generating random numbers is typically important in some applications that we do. For example, if we are writing a program that needs to shuffle a deck of cards, we can achieve that by swapping cards from random positions. In fact, many games requires random number generation because that makes each play unique from the previous one. Because if there is no randomness, then every time we play will feel the same. So below we try to show examples on how to generate Java Random Int values.
The multiply assign operator does two operations in one statement. First is that it multiplies the value of a variable on the left side with the evaluated value of the expression on the right side. The result is assigned back to the variable. This is why it is called a compounded assign operator is because it is a short hand for two operations. Below are examples on Multiply Assign Operator in Java.
XOR or the Binary Exclusive OR operation is a common bitwise operation in any language, including Java. Below are examples on how to use Binary Exclusive OR Assign Operator in the Java programming language:
In Java, Compounded Assignment Operator combines an operation and assignment into one statement, making code concise. Below is an example on how to do it with Binary OR operation. Which is we show examples on how to use Binary AND Assign Operator in Java.
Binary Right Shift Operation is like dividing a number by a power of two while preserving sign. Binary Right Shift Zero Fill is similar, where we are dividing a number by a power of 2, but unsigned. Which means we lose the sign of the original number after shifting, because we are replacing the digits shifted to the right by 0. Which turns the result into a positive number. This post will give examples on how to use Binary Right Shift Zero Fill Assign Operator in the Java Programming Language.
Binary Right Shift Operator is an efficient way of dividing a number by a power of 2 number, preserving the sign of the original number. Meaning this is a signed operation. We can combine this with assign operation to shorten our code. Below are examples on how we can use Binary Right Shift Assign Operator in java.
The Binary left Shift Operator is an efficient way of multiplying a number by a power of two. And when we do that operation, we also typically want to assign back the resulting product to the original variable. This is where the Binary Left Shift Assign Operator becomes handy. Below are some examples on how to use Binary Left Shift Assign Operator in Java.