• 19 September

    Return Empty Array in Java

    TL;DR To return empty Array in Java, you can use curly braces. [crayon-674f3efb29fab912351209/] or [crayon-674f3efb29fb2435408373/] 1. Introduction In this article, we will take a look on to How to return Empty array in java. We will look at different ways to achieve this with demonstrated working examples in detail. At first, let us have a […]

  • 18 September

    [Fixed] IllegalArgumentException: Bound must be positive

    In this post, we will see how to fix IllegalArgumentException: Bound must be positive in java. You will generally get this exception while generating random numbers using Random.nextInt() method. If you pass bound as 0 or less than 0, then you will get the exception. Let’s understand with the help of example: [crayon-674f3efb2a322467728122/] When you […]

  • 17 September

    Create List with One Element in Java

    In this post, we will see how to create List with One Element in java.. Using Collections.singletonList() This is best way to create List with single element if you need an immutable List. [crayon-674f3efb2a42b898227192/] Output [crayon-674f3efb2a42e512893783/] If you try to add element to the list, you will get exception [crayon-674f3efb2a42f519378459/] [crayon-674f3efb2a430260312503/] Using Array.asList() method [ […]

  • 17 September

    Replace null with Empty String in Java

    1. Introduction to the Problem Statement In Java development, handling null values effectively is crucial, especially when dealing with strings. A common requirement is to replace null strings with empty strings to avoid NullPointerException and maintain the flow of the application. If the given string is null, the output should be an empty string; otherwise, the […]

  • 17 September

    How to Get String Between Two Characters in Java

    In this post, we will see How to get String between two characters in java. Ways to get String between two characters in java. There are multiple ways to How to get String between two characters in java Using String’s substring() method To get String between two characters in java, use String’s substring() method. Find […]

  • 17 September

    Check if Date Is Weekend or Weekday in Java

    In this post, we will see how to check if Date is weekend or weekday in Java. Please note that we will consider Saturaday/Sunday as weekend and rest five days of week as weekdays. Using LocalDate’s getDayOfWeek() method We can use LocalDate’s getDayOfWeek() method to check if given date is weekend or weekday in Java. […]

  • 16 September

    How to Remove Extension from Filename in Java

    In this post, we will see how to remove extension from filename in java. Ways to Remove extension from filename in java There are multiple ways to remove extension from filename in java. Let’s go through them. Using substring() and lastIndexOf() methods You can first find last index of dot(.) using String’s lastIndexOf() method and […]

  • 16 September

    How to Write Array to File in Java

    In this post, we will see how to write array to file in java. Ways to Write Array to File in Java There are different ways to write array to file in java. Let’s go through them. Using BufferWriter Here are steps to write array to file in java: Create new FileWriter and wrap it […]

  • 16 September

    How to Take Integer Input in Java

    This article discusses the methods to take the integer input in Java. Variables In programs, data values are reserved in memory locations that can be identified by names (identifiers). Such named memory location which temporarily reserves data that can be changed while the program is running is called a variable. Let’s see how variables are […]