In this post under Java Collections, I will explain with example how to create synchronized map. Below is the complete code for your reference Main class 1 package core.collection; 2 3 import java.util.Collections; 4 import java.util.HashMap; 5 import java.util.Map; 6 7 public class SyncMapDemo { 8 public static void main(String args []) { 9 Map<Integer,…… Continue reading Creating a synchronized map
Category: Java
Creating a synchronized collection
In this post under Java Collections, I will show with example how to create a synchronized collection. Below is the complete main code for your reference. 1 package core.collection; 2 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.Collections; 6 import java.util.List; 7 8 public class SyncCollectionDemo { 9 public static void main(String[] args) {…… Continue reading Creating a synchronized collection
Collection to Enumeration conversion
In this post under Java Collections, I will show with example how to convert a collection to Enumeration. Below is the complete code for your reference. Main class 1 package core.collection; 2 3 import java.util.Collections; 4 import java.util.Enumeration; 5 import java.util.List; 6 import java.util.ArrayList; 7 8 public class ColToEnumDemo { 9 public static void main(String…… Continue reading Collection to Enumeration conversion
Copying elements from one list to another list
In this post under Java Collections, I will show with example how to copy elements from one list to another. Below is the complete code for your reference. Main class 1 package core.collection; 2 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.List; 6 7 public class ListCopyDemo { 8 public static void main(String []…… Continue reading Copying elements from one list to another list
Adding and accessing static members to Java Record
In this post under Java, I will show with example how to add and access static members in Java Record. Below is the structure of “Student” Record with static members Student 1 package core.record;2 3 public record Student(int id, String name, int age) {4 public static int noOfStudents;5 public static void display() {6 System.out.println(“Number of…… Continue reading Adding and accessing static members to Java Record
Simple Java Record Example
In this post under Java, I will introduce you with example to Java’s Record classes. Introduced in Java 16, is a immutable data class, whose main purpose is hold read only data. Below shows how to create Record class. Person Record package core.record;public record Person(int id, String name, int age) {} We save the file…… Continue reading Simple Java Record Example
Merging two character arrays
In this post under Java. I will show with example how to merge two character arrays into one. Below is the complete code for your reference. Main Class 1 package core.string; 2 3 public class Example1 { 4 public static void main(String[] args) { 5 char[] inputArray1 = {‘a’, ‘b’, ‘c’}; 6 char[] inputArray2 =…… Continue reading Merging two character arrays
Merging text files
In this post under Java I will with example how to merge two or more text files. Below is the complete code for your reference Main class 1 package io;2 3 import java.io.*;4 5 public class IOExample3 {6 private static int BYTES_TO_BE_READ = 1000;7 private char buffer[] = new char[BYTES_TO_BE_READ];8 9 public static void main(String[]…… Continue reading Merging text files
Creating text file of user specified size with random data
In this post under Java, I will show with example how to create a text file of user specified size with random data. Below is the complete code for you example Main class 1 package io;2 3 import java.io.BufferedWriter;4 import java.io.File;5 import java.io.FileWriter;6 import java.io.IOException;7 import java.util.Random;8 9 public class IOExample1 {10 private Random random;11…… Continue reading Creating text file of user specified size with random data
Uncompressing a gzip file
In this post under Java, I will show with example how to uncompress a gzip format file. For decompressing a gzip file, we will use java provided “GZIPInputStream” class. Below is the main code for your reference Main class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.IOException;…… Continue reading Uncompressing a gzip file