Arjun Thakur has Published 1025 Articles

Iterator vs forEach in Java

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 15:12:22

3K+ Views

Collections can be iterated easily using two approaches.Using for-Each loop − Use a foreach loop and access the array using object.Using Iterator − Use a foreach loop and access the array using object.DifferencesConcurrentModificationException − Using for-Each loop, if an object is modified, then ConcurrentModificationException can occur. Using iterator, this problem ... Read More

How to create a responsive image gallery with CSS

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 15:10:00

468 Views

To create a responsive image gallery with CSS, you can try to run the following codeExampleLive Demo                    div.myGallery {             border: 2px solid orange;          }          div.myGallery:hover ... Read More

Infinity or exception in Java when divide by 0?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 15:00:54

348 Views

Consider the following code snippet where we divide a number by 0.Example Live Demopublic class Tester{    public static void main(String[] args) {       double d = 100;       System.out.println(d/0);    } }OutputInfinityNow consider the following code snippet.Example Live Demopublic class Tester{    public static void main(String[] args) ... Read More

How to prevent Serialization to break a Singleton Class Pattern?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 14:38:06

680 Views

A Singleton pattern states that a class can have a single instance and multiple instances are not permitted to be created. For this purpose, we make the constructor of the class a private and return a instance via a static method. But using serialization, we can still create multiple instance ... Read More

How do you declare, initialize and access jagged arrays in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 14:18:11

215 Views

Declare Jagged ArrayA Jagged array is an array of arrays. You can declare a jagged array named scores of type int as −int [][] points;Initialize Jagged ArrayLet us now see how to initialize it.int[][] points = new int[][]{new int[]{10, 5}, new int[]{30, 40}, new int[]{70, 80}, new int[]{ 60, 70 ... Read More

How to select a random element from a C# list?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 14:12:45

44K+ Views

Firstly, set a list in C#.var list = new List{ "one", "two", "three", "four"};Now get the count of the elements and display randomly.int index = random.Next(list.Count); Console.WriteLine(list[index]);To select a random element from a list in C#, try to run the following code −Example Live Demousing System; using System.Collections.Generic; namespace Demo { ... Read More

How to inject JavaScript in WebBrowser control?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 12:59:49

2K+ Views

To inject JavaScript in WebBrowser control, use the following steps − Firstly, create a Windows Forms application in Visual Studio. Now, drag a WebBrowser control to the form Set the Url property. Right-click the project, choose to Add reference... → COM → Type Libraries Select "Microsoft HTML Object Library"  Add the following code to inject JavaScript.private void ... Read More

How to sort one dimensional array in descending order using non static method?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 12:44:58

221 Views

Set the unsorted list first.int[] list = {87, 45, 56, 22, 84, 65};Now use a nested for loop to sort the list that is passed to a function.for(int i=0; ilt; arr.Length; i++) {    for(int j=i+1; j

How to use the Copy(, ,) method of array class in C#

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 12:35:11

376 Views

As the name suggests the Array.Copy() method in C# is used to copy elements of one array to another array.The following is the syntax.Array.Copy(src, dest, length);Heresrc = array to be copieddest = destination arraylength = how many elements to copyThe following is an example showing the usage of Copy(, , ... Read More

What are Booleans types in C#?

Arjun Thakur

Arjun Thakur

Updated on 23-Jun-2020 12:28:29

178 Views

For the Boolean type, the bool keyword is used and is an alias of System.Boolean.It is used to declare variables to store the Boolean values, true and false.Let us see an example to learn how to use bool in C#.Exampleusing System; public class Demo {    static void Main() { ... Read More

Advertisements