Check If SortedSet and Specified Collection Contain Same Elements in Java

AmitDiwan
Updated on 06-Dec-2019 12:02:47

116 Views

To check if SortedSet and the specified collection contain the same elements, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedSet set1 = new SortedSet();       set1.Add(100);       set1.Add(200);       set1.Add(300);       SortedSet set2 = new SortedSet();       set2.Add(450);       set2.Add(550);       set2.Add(650);       set2.Add(750);       set2.Add(800);       Console.WriteLine("Does it contain the same elements? = "+set1.SetEquals(set2));    } }OutputThis will produce the following output −Does it contain the same elements? = FalseExampleLet us ... Read More

Getting Values in a SortedList Object in C#

AmitDiwan
Updated on 06-Dec-2019 11:59:40

126 Views

To get the values in a SortedList object, the code is as follows −Exampleusing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list = new SortedList();       list.Add(1, "One");       list.Add(2, "Two");       list.Add(3, "Three");       list.Add(4, "Four");       list.Add(5, "Five");       ICollection col1 = list.Values;       Console.WriteLine("Values...");       foreach(string s in col1)       Console.WriteLine(s);       ICollection col2 = list.Keys;       Console.WriteLine("Keys...");       foreach(int s in ... Read More

Get Value at Specified Index of SortedList Object in C#

AmitDiwan
Updated on 06-Dec-2019 11:55:44

120 Views

To get the value at the specified index of a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list = new SortedList();       list.Add("A", "Jacob");       list.Add("B", "Sam");       list.Add("C", "Tom");       list.Add("D", "John");       list.Add("E", "Tim");       list.Add("F", "Mark");       list.Add("G", "Gary");       Console.WriteLine("Value at index 2 = "+list.GetByIndex(2));       Console.WriteLine("Value at index 5 = "+list.GetByIndex(5));       Console.WriteLine("Value at index ... Read More

Check If ArrayList is Read-Only in C#

AmitDiwan
Updated on 06-Dec-2019 11:50:58

164 Views

To check if the ArrayList is read-only, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("ABC");       list1.Add("BCD");       list1.Add("CDE");       list1.Add("DEF");       list1.Add("EFG");       list1.Add("GHI");       list1.Add("HIJ");       list1.Add("IJK");       list1.Add("JKL");       list1.Add("KLM");       Console.WriteLine("Elements in ArrayList...");       foreach (string res in list1) {          Console.WriteLine(res);       } ... Read More

Create Empty HybridDictionary with Specified Case Sensitivity in C#

AmitDiwan
Updated on 06-Dec-2019 11:46:41

143 Views

To create an empty HybridDictionary with specified case sensitivity, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       HybridDictionary myDict = new HybridDictionary();       myDict.Add("A", "AB");       myDict.Add("B", "BC");       myDict.Add("C", "DE");       myDict.Add("D", "FG");       myDict.Add("e", "fg");       Console.WriteLine("Key/Value pairs...");       foreach(DictionaryEntry de in myDict)          Console.WriteLine("Key = "+de.Key + ", Value = " + de.Value);    } }OutputThis will produce the following output −Key/Value pairs... Key = A, ... Read More

Create Empty Case-Sensitive HybridDictionary Class in C#

AmitDiwan
Updated on 06-Dec-2019 11:42:51

117 Views

To create an empty case-sensitive HybridDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       HybridDictionary dict = new HybridDictionary(false);       dict.Add("A", "AB");       dict.Add("B", "BC");       dict.Add("C", "DE");       dict.Add("D", "de");       Console.WriteLine("Key/Value pairs...");       foreach(DictionaryEntry de in dict)          Console.WriteLine("Key = "+de.Key + ", Value = " + de.Value);    } }OutputThis will produce the following output −Key/Value pairs... Key = A,  Value = AB Key = B,  Value = BC Key = C,  Value = DE Key = D,  Value = deExampleLet us ... Read More

Create ArrayList with Specified Initial Capacity in C#

AmitDiwan
Updated on 06-Dec-2019 11:37:24

162 Views

To create an ArrayList having specified initial capacity, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList(5);       list1.Add("A");       list1.Add("B");       list1.Add("C");       list1.Add("D");       Console.WriteLine("Capacity in ArrayList1 = "+list1.Capacity);       Console.WriteLine("Elements in ArrayList1...");       foreach (string res in list1) {          Console.WriteLine(res);       }       ArrayList list2 = new ArrayList(10);       list2.Add("A");       ... Read More

Create Synchronized Wrapper for Hashtable in C#

AmitDiwan
Updated on 06-Dec-2019 11:32:12

145 Views

To create a synchronized wrapper for the Hashtable, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       Hashtable hash = new Hashtable();       hash.Add("1", "AB");       hash.Add("2", "CD");       hash.Add("3", "EF");       hash.Add("4", "GH");       hash.Add("5", "IJ");       hash.Add("6", "KL");       Console.WriteLine("Hashtable elements...");       foreach(DictionaryEntry d in hash) {          Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);       }       ... Read More

Create Synchronized Wrapper for ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 11:29:24

145 Views

To create a synchronized wrapper for the ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       arrList.Add("AB");       arrList.Add("CD");       arrList.Add("EF");       arrList.Add("GH");       arrList.Add("IJ");       arrList.Add("KL");       Console.WriteLine("ArrayList elements...");       foreach(string str in arrList) {          Console.WriteLine(str);       }       Console.WriteLine("ArrayList is synchronized? = "+arrList.IsSynchronized);    } }OutputThis will produce the following output −ArrayList elements... AB ... Read More

Check if ArrayList Has a Fixed Size in Java

AmitDiwan
Updated on 06-Dec-2019 11:26:13

193 Views

To check if the ArrayList has a fixed size, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");       list1.Add("Four");       list1.Add("Five");       Console.WriteLine("Elements in ArrayList...");       foreach (string res in list1) {          Console.WriteLine(res);       }       ArrayList list = ArrayList.Synchronized(list1);       Console.WriteLine("Is ArrayList synchronized? = "+list.IsSynchronized);       ... Read More

Advertisements