- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9291 Articles for Object Oriented Programming
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
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
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
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
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
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
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
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
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
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