AmitDiwan has Published 10744 Articles

Java Program for Bitonic Sort

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:50:29

276 Views

In Bitonic Sort, the comparision is in predefined sequence (Bitonic sequence), not dependent on the data to be sorted. Let us see an example for Bitonic Sort Java program −Example Live Demopublic class Demo{    void compare_swap(int my_arr[], int i, int j, int direction){       if ((my_arr[i] > my_arr[j] ... Read More

Java Program for Binary Search (Recursive)

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:47:14

7K+ Views

Following is the program for Recursive Binary Search in Java −Example Live Demopublic class Demo{    int rec_bin_search(int my_arr[], int left, int right, int x){       if (right >= left){          int mid = left + (right - left) / 2;          if ... Read More

Java Program for Anagram Substring Search

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:44:12

236 Views

Following is an example for Anagram Substring Search in Java −Example Live Demopublic class Demo{    static final int max_val = 256;    static boolean compare_vals(char my_arr_1[], char my_arr_2[]){       for (int i = 0; i < max_val; i++)       if (my_arr_1[i] != my_arr_2[i])       ... Read More

Java Program for Comb Sort

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:41:16

265 Views

The Comb Sort in Java eliminates the smaller values situated to the end of the list and the inversions are removed oby by one. Let us see an example −Example Live Demoimport java.util.Arrays; public class Demo{    void comb_sort(int nums[]){       int len_gap = nums.length;       float ... Read More

Java Program for Counting Sort

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:39:15

209 Views

The Counting Sort counts the number of objects having distinct key values. Let us see an example −Note − The below code can be used with negative numbers as well.Example Live Demoimport java.util.*; public class Demo{    static void count_sort(int[] arr){       int max_val = Arrays.stream(arr).max().getAsInt();       ... Read More

Java Numeric Promotion in Conditional Expression

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:20:21

154 Views

The conditional operator (? :) leverages the output of one value (which is a bool) to decide which expression has to be evaluated next. Let us see an example −Example Live Demoimport java.io.*; public class Demo{    public static void main (String[] args){       Object my_obj = true ? ... Read More

Java Lambda Expression with Collections

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:16:54

873 Views

Sorting the elements of a list using lambda expression −Example Live Demoimport java.util.*; public class Demo{    public static void main(String[] args){       ArrayList my_arr = new ArrayList();       my_arr.add(190);       my_arr.add(267);       my_arr.add(12);       my_arr.add(0);       System.out.println("Before sorting, ... Read More

Java ConcurrentHashMap - clear()

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:06:38

323 Views

The clear function is used to clear up the mapping between the key value pairs. This way, the ConcurrentHashMap mappings would be cleared.Syntaxpublic void clear()Let us see an example −Example Live Demoimport java.util.concurrent.ConcurrentHashMap; import java.util.*; public class Demo{    public static void main(String[] args){       Map my_map = new ... Read More

Java Concurrency – sleep() method

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 09:01:30

419 Views

The sleep functionThis sleep function is used to ensure that the currently executing thread goes to sleep for a specific amount of milliseconds which is passed as a parameter to the function. The thread stops executing for that number of milliseconds.Let us see an exampleExample Live Demoimport java.lang.*; public class Demo ... Read More

Jar files in Java

AmitDiwan

AmitDiwan

Updated on 04-Jul-2020 08:55:10

745 Views

JAR is a file format that helps in aggregating Java class file, along with its associated metadata and resources into a single file.Creation of a JAR file − The jar cf command can be used, where ‘cf’ means creating the file.jar cf jar_file_name files_to_compressOnce a jar file has been created, ... Read More

Advertisements