Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2091 of 3366
1K+ Views
Java 9 provides factory methods to create immutable lists, sets, and maps. It can be useful to create empty or non-empty collection objects. In Java 8 and earlier versions, we can use collection class utility methods like unmodifiableXXX to create immutable collection objects. If we need to create an immutable list, then use the Collections.unmodifiableList() method. What does Immutable mean? An object is considered immutable if its state cannot change after it is constructed. Any modification creates a new object instead. String name = "TutorialsPoint"; name = name + "10"; Here, "TutorialsPoint" is an immutable string, and we cannot modify it directly. Instead, we use the ... Read More
549 Views
In this article, we will learn about useful commands in JShell. Java 9 has introduced a new interactive tool called JShell. This tool can be used to execute, test user-friendly and easy way of Java classes, interfaces, enums, objects, statements and etc. Different Useful Commands in JShell Below are some of the important commands in JShell: /open /var /types /methods /list /help /open To execute a script after JShell has started, we will use ... Read More
407 Views
JShell is a new java shell tool released in java 9. It is the first official REPL (Read-Evaluate-Print-Loop) application. This tool helps in executing and evaluating simple java programs and logics such as statements, loops, expressions, and etc. Java REPL provides a simple programming environment in the command prompt. It can read the input, evaluate it and print the output.In the below example we can able to create a class and object in JShell using command prompt.Examplejshell> class Employee { ...> private String name; ...> Employee(String name) { ...> this.name=name; ...> } ...> ... Read More
766 Views
StackWalker API allows easy filtering and lazy access to execute tasks within any method. It is an efficient API for obtaining stack trace information in Java 9.There are three new important classes in StackWalker API: StackWalker, StackWalker.StackFrame and StackWalker.Option.StackWalker − It is the main class in StackWalker API. We traverse stack frames by using StackWalker.forEach() method and get caller class in an efficient way by calling StackWalker.getCallerClass() method. We walk through stack traces and applying a function on a stream of stack frames by using StackWalker.walk() method.StackWalker.StackFrame − It is a static nested class of StackWalker and represents method invocation return by StackWalker. It has methods ... Read More
234 Views
In this tutorial, we will be discussing a program to find the number of sub-sequences having product k) { discard_count += power(2, n - i); return; } if (i == n) return; float rem = prefix[n - 1] - prefix[i]; if (sum + a[i] + rem > k) solve(i + 1, n, sum + a[i], k, a, prefix); if (sum + rem > k) solve(i + 1, n, sum, k, a, prefix); } int countSubsequences(const int* arr, ... Read More
156 Views
In this tutorial, we will be discussing a program to find the number of walks from a source to a destination with exactly k edges.For this we will be provided with a graph and the values of source and destination. Our task is to find all the possible paths starting from the source to the destination having exactly k edges.Example Live Demo#include using namespace std; #define V 4 //counting walks using recursion int countwalks(int graph[][V], int u, int v, int k){ if (k == 0 && u == v) return 1; if (k == 1 && graph[u][v]) return 1; if (k
119 Views
In this tutorial, we will be discussing a program to find the number of prefixes of the binary array which are divisible by x.For this we will be provided with binary array and a value x. Our task is to find the number of elements whose prefixes are divisible by given value x.Example Live Demo#include using namespace std; //counting the elements with prefixes //divisible by x int count_divx(int arr[], int n, int x){ int number = 0; int count = 0; for (int i = 0; i < n; i++) { number = number ... Read More
237 Views
In this tutorial, we will be discussing a program to find the number of quadruples from four arrays such that their XOR equals to x.For this we will be provided with four arrays and a value x. Our task is to count all the quadruples whose XOR is equal to the given value x.Example Live Demo#include using namespace std; //counting quadruples with XOR equal to x int count_quad(int a[], int b[], int c[], int d[], int x, int n){ int count = 0; for (int i = 0 ; i < n ; i++) for (int ... Read More
193 Views
In this tutorial, we will be discussing a program to find the number of prime length palindromic strings.For this we will be provided with a string. Our task is to count all the sub strings which are palindromes and have prime lengths.Example Live Demo#include using namespace std; //checking for a palindrome bool if_palin(string str, int i, int j){ while (i < j) { if (str[i] != str[j]) return false; i++; j--; } return true; } //counting palindrome with prime length int count_prime(string str, int ... Read More
264 Views
In this tutorial, we will be discussing a program to find the number of sub-arrays having sum divisible by k.For this we will be provided with an array and a value k. Our task is to find the number of sub arrays that are having their sum as equal to the given value k.Example Live Demo#include using namespace std; //counting subarrays with k sum int count_subarray(int arr[], int n, int k){ int mod[k]; memset(mod, 0, sizeof(mod)); int cumSum = 0; for (int i = 0; i < n; i++) { cumSum += arr[i]; ... Read More