Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 8 of 81

Find frequency of each word in a string in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 2K+ Views

In order to get frequency of each in a string in Java we will take help of hash map collection of Java.First convert string to a character array so that it become easy to access each character of string.Now compare for each character that whether it is present in hash map or not in case it is not present than simply add it to hash map as key and assign one as its value.And if character is present than find its value which is count of occurrence of this character in the string (initial we put as 1 when it ...

Read More

Clear a Hashtable in C#

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 512 Views

Clear a Hashtable, using the Clear() method in C#.The following is our Hashtable −Hashtable h = new Hashtable(); h.Add(1, "Amit"); h.Add(2, "Sachin"); h.Add(3, "Rahul");Use the clear method.h.Clear();If you will now try to display the Hashtable, nothing would get display since the Hashtable is empty.Exampleusing System; using System.Collections; public class Demo {    public static void Main() {       Hashtable h = new Hashtable();       h.Add(1, "Amit");       h.Add(2, "Sachin");       h.Add(3, "Rahul");       Console.WriteLine("Keys and Values list:");       foreach (var key in h.Keys ) {       ...

Read More

How to handle empty collections in C#

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 479 Views

To handle empty collections, use the DefaultIfEmpty() method in C#.If an array is empty, then using this method will show the default method instead of displaying an error.Let’s say we have an empty list.List myList = new List();Now, use DefaultIfEmpty() method to display the default value.myList.DefaultIfEmpty();Exampleusing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       List myList = new List();       var res = myList.DefaultIfEmpty();       foreach (var a in res) {          Console.WriteLine(a);       }    } }Output0

Read More

How to sort a list in C#?

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 264 Views

Set a list with some values. Here, we have a list of strings.var cars = new List() {"Mercedes", "Audi", "Jaguar" };To sort, simply use Sort() method.cars.Sort();The following is an example showing how to sort a list in C#.Exampleusing System; using System.Collections.Generic; public class Program {    public static void Main() {       var cars = new List() {"Mercedes", "Audi", "Jaguar" };       Console.WriteLine("Original Array =");       foreach (var name in cars) {          Console.WriteLine(name);       }       // sort       cars.Sort();       Console.WriteLine("Sorted Array =");       foreach (var name in cars) {          Console.WriteLine(name);       }    } }OutputOriginal Array = Mercedes Audi Jaguar Sorted Array = Audi Jaguar Mercedes

Read More

How to convert JS date time to MySQL datetime?

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 1K+ Views

We can convert JS date time to MySQL datetime with the help of toISOString() function.Let us see an example of JavaScript.Example           Web Page Design                document.writeln(new Date().toISOString().slice(0, 19).replace('T', ' '));              Current Date is displayed above... OutputThe following is the output.2018-11-23 11:14:38 Current Date is displayed above...

Read More

C# Queryable SequenceEqual() Method

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 153 Views

To check whether two sequences are equal or not, use the SequenceEqual() method.Firstly, set the sequences.Employee emp1 = new Employee { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 }; Employee emp2 = new Employee { EmployeeRank = 5, EmpName = "Raman", EmpMarks = 95 }; List employee1 = new List { emp1, emp2 }; List employee2 = new List { emp1, emp2 };Now, find whether the sequences are equal or not.employee1.AsQueryable().SequenceEqual(employee2);Here is the example that shows the result.Exmapleusing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       Employee emp1 ...

Read More

C# Numeric (“N”) Format Specifier

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 2K+ Views

The numeric ("N") format specifier converts a number to a string of the following form −"-d,ddd,ddd.ddd…"Above,"-" is a negative number symbol if required,"d" is a digit (0-9), "," indicates a group separator,"." is a decimal point symbolExampleusing System; using System.Globalization; class Demo {    static void Main() {       double val1 = -5566.789;       Console.WriteLine(val1.ToString("N", CultureInfo.InvariantCulture));       int val2 = 87987766;       Console.WriteLine(val2.ToString("N3", CultureInfo.InvariantCulture));    } }Output-5,566.79 87,987,766.000

Read More

Replace All Elements Of ArrayList with with Java Collections

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 2K+ Views

In order to replace all elements of ArrayList with Java Collections, we use the Collections.fill() method. The static void fill(List list, Object element) method replaces all elements in the list with the specified element in the argument.Declaration −The java.util.Collections.fill() method is declared as follows −public static void fill(List

Read More

How do we access elements from the two-dimensional array in C#?

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 4K+ Views

A 2-dimensional array can be thought of as a table, which has x number of rows and y number of columns.An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array.int x = a[1, 1]; Console.WriteLine(x);Let us see an example that shows how to access elements from two-dimensional array.Exampleusing System; namespace Demo {    class MyArray {       static void Main(string[] args) {          /* an array with 5 rows and 2 columns*/          int[, ] a = new int[5, 2] {{0, ...

Read More

Swap elements of ArrayList with Java collections

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 10K+ Views

In order to swap elements of ArrayList with Java collections, we need to use the Collections.swap() method. It swaps the elements at the specified positions in the list.Declaration −The java.util.Collections.swap() method is declared as follows −public static void swap(List list, int i, int j)where i is the index of the first element to be swapped, j is the index of the other element to be swapped and list is the list where the swapping takes place.Let us see a program to swap elements of ArrayList with Java collections −Exampleimport java.util.*; public class Example {    public static void main ...

Read More
Showing 71–80 of 810 articles
« Prev 1 6 7 8 9 10 81 Next »
Advertisements