Following are the notable differences between HashTable and HashMap classes in Java. HashTableHashMapSynchronizedHashTable is synchronized.HashMap is not synchronized.Thread SafeHashTable is thread safe.HashMap is not thread safe.Null objectsHashTable does not allows null keys or null values.HashMap allows one null key and multiple null values.PerformanceHashTable is faster.HashMap is slower than HashTable.Since Java Version1.21.5Exampleimport java.util.HashMap; import java.util.Hashtable; import java.util.Map; public class Tester { public static void main(String args[]) { Map map = new HashMap(); map.put("1", "One"); map.put("2", "Two"); map.put("3", "Three"); map.put("5", "Five"); ... Read More
HashMap, TreeMap and LinkedHashMap all implements java.util.Map interface and following are their characteristics.HashMapHashMap has complexity of O(1) for insertion and lookup.HashMap allows one null key and multiple null values.HashMap does not maintain any order.TreeMapTreeMap has complexity of O(logN) for insertion and lookup.TreeMap does not allow null key but allow multiple null values.TreeMap maintains order. It stores keys in sorted and ascending order.LinkedHashMapLinkedHashMap has complexity of O(1) for insertion and lookup.LinkedHashMap allows one null key and multiple null values.LinkedHashMap maintains order in which key-value pairs are inserted.Exampleimport java.util.HashMap; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; public class Tester { ... Read More
The following is the list of escape characters in C# −Escape characterDescriptionPattern\aMatches a bell character, \u0007.\a\bIn a character class, matches a backspace, \u0008.[\b]{3, }\tMatches a tab, \u0009.(\w+)\t\rMatches a carriage return, \u000D. (\r is not equivalent to the newline character, .)\r(\w+)\vMatches a vertical tab, \u000B.[\v]{2, }\fMatches a form feed, \u000C.[\f]{2, }Matches a new line, \u000A.\r(\w+)\eMatches an escape, \u001B.\ennUses octal representation to specify a character (nnnconsists of up to three digits).\w\040\w\x nnUses hexadecimal representation to specify a character (nn consists of exactly two digits).\w\x20\w\c X\c xMatches the ASCII control character that is specified by X or x, where X or x is ... Read More
The System.Math class in C# provides methods are properties to perform mathematical operations, trigonometric, logarithmic calculations, etc.Some of its methods include −Sr.NoMethod & Description1Abs(Decimal)Returns the absolute value of a Decimal number.2Abs(Double)Returns the absolute value of a double-precision floating-point number.3Abs(Int16)Returns the absolute value of a 16-bit signed integer.4Abs(Int32)Returns the absolute value of a 32-bit signed integer.5Abs(Int64)Returns the absolute value of a 64-bit signed integer.6Abs(SByte)Returns the absolute value of an 8-bit signed integer.7Abs(Single)Returns the absolute value of a single-precision floating-point number.8Acos(Double)Returns the angle whose cosine is the specified number.9Asin(Double)Returns the angle whose sine is the specified number.10Atan(Double)Returns the angle whose tangent is ... Read More
With C#, you can easily work with Logarithms. It has the following methods for Log as well as Log base 10.Sr.NoMethod & Description1Log(Double)Returns the natural (base e) logarithm of a specified number.2LogDouble)(Double,Returns the logarithm of a specified number in a specified base.3Log10(Double)Returns the base 10 logarithm of a specified number.Let us see an example to work with Log functions in C# −Exampleusing System; class Demo { static void Main() { double val1 = Math.Log(1); Console.WriteLine(val1); double val2 = Math.Log10(1000); Console.WriteLine(val2); } }
A class definition starts with the keyword class followed by the class name; and the class body enclosed by a pair of curly braces.The following is the syntax − class class_name { // member variables variable1; variable2; ... variableN; // member methods method1(parameter_list) { // method body } method2(parameter_list) { // method body } ... methodN(parameter_list) { // method body } }The following are the conventions ... Read More
To start learning C#, firstly you should have computer knowledge. With that, if you have a prior learning experience in C or C#, then it would be great.To start with C#, first install Visual Studio. The current version is Visual Studio 2017.If you want to avoid the hassles of installing a bulky Visual Studio IDE, then you can begin with Online Compilers. The top online compilers to run C# programs are −Coding groundDotNetFiddleBoth of the above are intelligent compilers. Just go there, type the C# code and run it. That’s it!
java.util.Deque interface is a subtype of java.util.Queue interface which supports insertion and removal of elements at both ends.Interface Declarationpublic interface Deque extends QueueArrayDeque ClassThe java.util.ArrayDeque class provides resizable-array and implements the Deque interface. Following are the important points about Array Deques −Array deques have no capacity restrictions so they grow as necessary to support usage.They are not thread-safe; in the absence of external synchronization.They do not support concurrent access by multiple threads.Null elements are prohibited in the array deques.They are faster than Stack and LinkedList.This class and its iterator implement all of the optional methods of the Collection and Iterator ... Read More
Following are the notable differences between ArrayList and CopyOnWriteArrayList classes in Java. ArrayListCopyOnWriteArrayListSynchronizedArrayList is not synchronized.CopyOnWriteArrayList is synchronized.Thread SafeArrayList is not thread safe.CopyOnWriteArrayList is thread safe.Iterator typeArrayList iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.CopyOnWriteArrayList is fail-safe and it will never throw ConcurrentModificationException during iteration. The reason behind the it that CopyOnWriteArrayList creates a new arraylist every time it is modified.Remove OpearationArrayList iterator supports removal of element during iteration.CopyOnWriteArrayList.remove() method throws exception if elements are tried to be removed during iteration.PerformanceArrayList is faster.CopyOnWriteArrayList is slower than ArrayList.Since Java Version1.21.5Exampleimport java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList; public class Tester { ... Read More
A 2-dimensional array is a list of one-dimensional arrays.Two-dimensional arrays may be initialized by specifying bracketed values for each row.int [,] a = new int [2,2] { {0, 1} , {4, 5} };The following is an example showing how to work with two-dimensional arrays in C# −using System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { /* an array with 3 rows and 2 columns*/ int[,] a = new int[3, 2] {{0,0}, {1,2}, {2,4} }; int i, j; /* output each array element's value */ for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { Console.WriteLine("a[{0},{1}] = {2}", i, j, a[i,j]); } } Console.ReadKey(); } } }
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP