Core java
17 SeptemberCreate 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-6a289cd8e7cc4994915673/] Output [crayon-6a289cd8e7cce401299003/] If you try to add element to the list, you will get exception [crayon-6a289cd8e7cd1305530582/] [crayon-6a289cd8e7cd2571931451/] Using Array.asList() method [ […]
17 SeptemberReplace 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 SeptemberHow 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 SeptemberCheck 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 SeptemberHow 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 SeptemberHow 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 SeptemberHow 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 […]
16 SeptemberConvert String to Path in Java
In this post, we will see how to convert String to Path in Java. Using Paths’get() method [ Java 7 ] To convert String to Path, use jva.nio.file.Paths's get() method. It is a static method. Here is an example: [crayon-6a289cd8ea685535994226/] Output: [crayon-6a289cd8ea68a540830331/] You can also join multiple strings using Paths‘s get() method. It will join […]
15 SeptemberHow to Replace Space with Underscore in Java
Learn about how to replace space with underscore in java. Replace space with underscore in java 1. Using replace() method Use String’s replace() method to replace space with underscore in java. String’s replace() method returns a string replacing all the CharSequence to CharSequence. Syntax of replace() method: [crayon-6a289cd8eaba1335567680/] [crayon-6a289cd8eaba7955475035/] Output: This_blog_is_Java2blog As you can see, […]