• 13 December

    Java Random nextInt

    In this tutorial, we will see Java Random nextInt method.It is used to generate random integer. There are two overloaded versions for Random nextInt method. nextInt() Syntax [crayon-6a29754c16ce8272095108/] Here random is object of the java.util.Random class. Return returns random integer. Example Let’s see a very simple example: [crayon-6a29754c16cff461395862/] Output: Random Integer: 1326186546 Random Integer: 203489674 […]

  • 13 December

    Java – generate random String

    In this tutorial, we will see how to generate random String in java. There are many ways to generate random String.Let’s explore some of ways to generate random String. Using simple java code with Random You can use SecureRandom class to generate random String for you. Let’s understand with the help of example. [crayon-6a29754c1720a616235734/] Output: […]

  • 13 December

    Random number generator in java

    In this tutorial, we will see about random number generators.You might have requirement where you want to generate random numbers to perform some operation. For example: Let’s say you are creating a game which uses dice for each player’s turn. You can put logic to generate random number whenever the player uses dice. There are […]

  • 17 November

    Java program to print floyd’s triangle

    In this post, we will see how to print Floyd’s triangle in java. Problem You need to print Floyd’s triangle as below for n=5. Floyd’s triangle **************** 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Floyd’s triangle in java Let’s create class "FloydTriangleMainExample.java" as below [crayon-6a29754c1974c066418768/] When you […]

  • Print sequence using 3 threads in java
    17 November

    Print Numbers Using Multiple Threads in Java

    In this post, we will see how to print numbers using multiple threads in java.It is similar to printing odd-even numbers using two threads in java. Problem You are given 3 threads. You need to print sequence using these 3 threads.You need to print in natural order up to MAX. For example: Let’s say you […]

  • 10 November

    Java String matches example

    In this post, we are going to see String’s matches method. String’s matches method String matches method is used to check whether the string is matched with the given regular expression.In normal terms, we can pass various regular expressions to check if the specified string matches with that regular expression.If the matches get successful return […]

  • 10 November

    Java List to String

    In this post, we will see how to convert List to String in java. Following are the ways to convert list into String: Using StringBuilder We can use StringBuilder class to convert List to String. StringBuilder is the best approach if you have other than String Array, List.We can add elements in the object of […]

  • 10 November

    Java Convert Array to List

    In this post, we will see how to convert array to list in java. There are may ways to convert array to list: By using Arrays.asList(): This is an easy method to convert Array into list.We just need to pass array as parameter to asList() method.It is a Static method available in Arrays class so, […]

  • 10 November

    Java convert List to Array

    In this post, we will see how to convert List to Array in java. There are many ways to convert List to Array in java Using toArray() method We can use toArray() method to convert List to String. We can either pass a array of size as List’s length or we can pass empty array. […]