Found 9291 Articles for Object Oriented Programming

How to disable future dates in JavaScript Datepicker?

AmitDiwan
Updated on 14-Jul-2020 17:20:31

12K+ Views

In order to disable future dates, you need to use maxDate and set the current date. Following is the JavaScript code −Example Live Demo Document The selected date is as follows:    $(document).ready(function () {       var currentDate = new Date();       $('.disableFuturedate').datepicker({       format: 'dd/mm/yyyy',       autoclose:true,       endDate: "currentDate",       maxDate: currentDate       }).on('changeDate', function (ev) {          $(this).datepicker('hide');       });       $('.disableFuturedate').keyup(function () {     ... Read More

Java program to find Maximum and minimum element’s position in a list

AmitDiwan
Updated on 07-Jul-2020 09:54:25

316 Views

To find the maximum and minimum element’s position in a list, the Java program is as follows −Example Live Demoimport java.util.*; import java.util.Arrays; import java.util.Collections; public class Demo{    public static int index_val(int my_arr[], int t){       if (my_arr == null){          return -1;       }       int len = my_arr.length;       int i = 0;       while (i < len){          if (my_arr[i] == t){             return i;          } else {         ... Read More

Program to Iterate over a Stream with Indices in Java 8

AmitDiwan
Updated on 07-Jul-2020 09:52:03

409 Views

To iterate over a Stream with Indices in Java 8, the code is as follows −Example Live Demoimport java.util.stream.IntStream; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; public class Demo{    public static void main(String[] args){       String[] my_array = { "T", "h", "i", "s", "s", "a", "m", "p", "l", "e" };       AtomicInteger my_index = new AtomicInteger();       System.out.println("The elements in the string array are :");       Arrays.stream(my_array).map(str -> my_index.getAndIncrement() + " -> " + str).forEach(System.out::println);    } }OutputThe elements in the string array are : 0 -> T 1 -> h 2 -> i 3 ... Read More

Java program to print unique values from a list

AmitDiwan
Updated on 07-Jul-2020 09:48:34

891 Views

To print unique values from a List in Java, the code is as follows −Example Live Demoimport java.io.*; public class Demo{    static void distinct_vals(int my_arr[], int len){       for (int i = 0; i < len; i++){          int j;          for (j = 0; j < i; j++)          if (my_arr[i] == my_arr[j])             break;          if (i == j)          System.out.print( my_arr[i] + " ");       }    }    public static void main ... Read More

Java program to find all close matches of input string from a list

AmitDiwan
Updated on 07-Jul-2020 09:46:46

505 Views

To find all close matches of input string from a list, the Java code is as follows −Example Live Demoimport java.io.*; import java.util.*; public class Demo{    static String string_encoding(String str){       HashMap my_map = new HashMap();       String result = "";       int i = 0;       char ch;       for (int j = 0; j < str.length(); j++) {          ch = str.charAt(j);          if (!my_map.containsKey(ch))          my_map.put(ch, i++);          result += my_map.get(ch);       } ... Read More

Java program to remove all duplicates words from a given sentence

AmitDiwan
Updated on 07-Jul-2020 09:44:10

525 Views

To remove all duplicate words from a given sentence, the Java code is as follows −Example Live Demoimport java.util.Arrays; import java.util.stream.Collectors; public class Demo{    public static void main(String[] args){       String my_str = "This is a is sample a sample only.";       my_str = Arrays.stream(my_str.split("\s+")).distinct().collect(Collectors.joining(" "));       System.out.println(my_str);    } }OutputThis is a sample only.A class named Demo contains the main function. In this function, a String object is defined. It is split based on the spaces and only distinct words of the string are joined together using space as a separator and displayed ... Read More

Java program to sort words of sentence in ascending order

AmitDiwan
Updated on 07-Jul-2020 09:41:56

5K+ Views

To sort words of sentence in ascending order, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{    static void sort_elements(String []my_str, int n){       for (int i=1 ;i= 0 && temp.length() < my_str[j].length()){             my_str[j+1] = my_str[j];             j--;          }          my_str[j+1] = temp;       }    }    public static void main(String args[]){       String []my_arr = {"This", "is", "a", "sample"};       int len = my_arr.length;       sort_elements(my_arr,len);       System.out.print("The sorted array is : ");       for (int i=0; i

Java program to split the Even and Odd elements into two different lists

AmitDiwan
Updated on 07-Jul-2020 09:16:21

727 Views

To split the Even and Odd elements into two different lists, the Java code is as follows −Example Live Demoimport java.util.Scanner; public class Demo{    public static void main(String[] args){       int n, j = 0, k = 0;       Scanner s = new Scanner(System.in);       System.out.println("Enter the number of elements required :");       n = s.nextInt();       int my_arr[] = new int[n];       int odd_vals[] = new int[n];       int even_vals[] = new int[n];       System.out.println("Enter the elements of the array(even and add numbers) ... Read More

Java program to find missing and additional values in two lists

AmitDiwan
Updated on 07-Jul-2020 08:36:21

1K+ Views

To find missing and additional values in two lists, the Java program is as follows −Example Live Demoimport java.util.*; public class Demo{    public static void main(String[] args){       List my_list_1 = new ArrayList();       List my_list_2 = new ArrayList();       my_list_1.add(new Integer("101"));       my_list_1.add(new Integer("90"));       my_list_1.add(new Integer("34"));       my_list_2.add(new Integer("34"));       my_list_2.add(new Integer("67"));       my_list_2.add(new Integer("90"));       for(int i = 0; i < my_list_1.size(); i++){          if (my_list_2.contains(my_list_1.get(i)))          continue;           ... Read More

Java program to generate random numbers within a given range and store in a list

AmitDiwan
Updated on 07-Jul-2020 09:15:25

293 Views

To generate random numbers in a given range, the Java code is as follows −Example Live Demoimport java.util.Random; import java.util.*; public class Demo{    public static void main(String args[]){       Random my_rand = new Random();       List my_list_1 = new ArrayList();       int v_1 = my_rand.nextInt(1000);       int v_2 = my_rand.nextInt(967);       int v_3 = my_rand.nextInt(1050);       int v_4 = my_rand.nextInt(10000);       int v_5 = my_rand.nextInt(100);       my_list_1.add(v_1);       my_list_1.add(v_2);       my_list_1.add(v_3);       my_list_1.add(v_4);       my_list_1.add(v_5);   ... Read More

Advertisements