Blog

python tutorials and learn python

Created with Sketch.

Java Program to Convert Map (HashMap) to List

Java Program to Convert Map (HashMap) to List In this program, you’ll learn different techniques to convert a map to a list in Java. Example 1: Convert Map to List import java.util.*; public class MapList { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); map.put(1, “a”); map.put(2, “b”); map.put(3, “c”); map.put(4,…
Read more

Java Program to Get Current Working Directory

Java Program to Get Current Working Directory In this program, you’ll learn to get the current working directory in Java. Example 1: Get current working directory public class CurrDirectory { public static void main(String[] args) { String path = System.getProperty(“user.dir”); System.out.println(“Working Directory = ” + path); } } When you run the program, the output…
Read more

Java Program to Convert List (ArrayList) to Array and Vice-Versa

Java Program to Convert List (ArrayList) to Array and Vice-Versa In this program, you’ll learn to convert a list to an array using toArray() and array to list using asList() in Java. Example 1: Convert list to array import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ListArray { public static void main(String[] args) { List<String>…
Read more

Java Program to Join Two Lists

Java Program to Join Two Lists In this program, you’ll learn different techniques to join two lists in Java. Example 1: Join Two Lists using addAll() import java.util.ArrayList; import java.util.List; public class JoinLists { public static void main(String[] args) { List<String> list1 = new ArrayList<String>(); list1.add(“a”); List<String> list2 = new ArrayList<String>(); list2.add(“b”); List<String> joined =…
Read more

Java Program to Add Two Dates

Java Program to Add Two Dates In this program, you’ll learn to add two dates in Java using Calendar. Since, Java epoch is 1970, any time represented in a Date object will not work. This means, your Dates will start from 1970 and when two Date objects are added, the sum misses by about 1970…
Read more

Java Program to Convert Milliseconds to Minutes and Seconds

Java Program to Convert Milliseconds to Minutes and Seconds In the above program, you’ll learn to convert milliseconds to minutes and seconds individually, and together in Java. Example 1: Convert milliseconds to minutes and seconds individually import java.util.concurrent.TimeUnit; public class Milliseconds { public static void main(String[] args) { long milliseconds = 1000000; // long minutes…
Read more

Java Program to Get Current Date/TIme

Java Program to Get Current Date/TIme In this program, you’ll learn to get the current date and time in different formats in Java.   Example 1: Get Current date and time in default format import java.time.LocalDateTime; public class CurrentDateTime { public static void main(String[] args) { LocalDateTime current = LocalDateTime.now(); System.out.println(“Current Date and Time is:…
Read more

Java Program to Check if a String is Empty or Null

Java Program to Check if a String is Empty or Null In this program, you’ll learn to check if a string is empty or null using if-else statement and functions in Java. Example 1: Check if String is Empty or Null public class Null { public static void main(String[] args) { String str1 = null;…
Read more

Java Program to Check if An Array Contains a Given Value

Java Program to Check if An Array Contains a Given Value In this program, you’ll learn to check if an array contains a given value in Java. Example 1: Check if Int Array contains a given value public class Contains { public static void main(String[] args) { int[] num = {1, 2, 3, 4, 5};…
Read more

Java Program to Convert Character to String and Vice-Versa

Java Program to Convert Character to String and Vice-Versa In this program, you’ll learn to convert a character (char) to a string and vice-versa in Java. Example 1: Convert char to String public class CharString { public static void main(String[] args) { char ch = ‘c’; String st = Character.toString(ch); // Alternatively // st =…
Read more