Programming Articles - Page 2260 of 3366

Adding new node or value at the end of LinkedList in C#

AmitDiwan
Updated on 06-Dec-2019 10:18:15

162 Views

To add new node or value at the end of LinkedList, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       LinkedList list = new LinkedList();       list.AddLast("A");       list.AddLast("B");       list.AddLast("C");       list.AddLast("D");       list.AddLast("E");       list.AddLast("F");       Console.WriteLine("Count of nodes = " + list.Count);       Console.WriteLine("Elements in LinkedList...");       foreach (string res in list) {          Console.WriteLine(res);       }       ... Read More

Adding elements to the end of the ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 10:15:10

218 Views

To add elements to the end of the ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list = new ArrayList();       list.Add("Andy");       list.Add("Gary");       list.Add("Katie");       list.Add("Amy");       Console.WriteLine("Elements in ArrayList...");       foreach (string res in list) {          Console.WriteLine(res);       }       string[] strArr = { "John", "Jacob" };       list.AddRange(strArr);       Console.WriteLine("Elements in ArrayList...UPDATED");     ... Read More

How to write the comparator as a lambda expression in Java?

raja
Updated on 06-Dec-2019 10:26:25

5K+ Views

A lambda expression is an anonymous method and doesn't execute on its own in java. Instead, it is used to implement a method defined by the functional interface. A lambda expression used with any functional interface and Comparator is a functional interface. The Comparator interface has used when sorting a collection of objects compared with each other.In the below example, we can sort the employee list by name using the Comparator interface.Exampleimport java.util.ArrayList; import java.util.Collections; import java.util.List; class Employee {    int id;    String name;    double salary;    public Employee(int id, String name, double salary) {       super();   ... Read More

Adding an element to the List in C#

AmitDiwan
Updated on 06-Dec-2019 10:11:06

269 Views

To add an element to the List, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list = new List();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       list.Add("Six");       list.Add("Seven");       list.Add("Eight");       Console.WriteLine("Enumerator iterates through the list elements...");       List.Enumerator demoEnum = list.GetEnumerator();       while (demoEnum.MoveNext()) {          string res = demoEnum.Current;     ... Read More

Check if SortedDictionary contains the specified key or not in C#

AmitDiwan
Updated on 06-Dec-2019 10:08:09

156 Views

To check if SortedDictionary contains the specified key or not, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedDictionary sortedDict = new SortedDictionary();       sortedDict.Add(100, "Mobile");       sortedDict.Add(200, "Laptop");       sortedDict.Add(300, "Desktop");       sortedDict.Add(400, "Speakers");       sortedDict.Add(500, "Headphone");       sortedDict.Add(600, "Earphone");       Console.WriteLine("SortedDictionary key-value pairs...");       IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();       while (demoEnum.MoveNext())       Console.WriteLine("Key = " + demoEnum.Key + ", Value = ... Read More

Check if Hashtable is synchronized C#

AmitDiwan
Updated on 06-Dec-2019 10:04:21

159 Views

To check if Hashtable is synchronized, 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("One", "Katie");       hash.Add("Two", "John");       hash.Add("Three", "Barry");       hash.Add("Four", "");       hash.Add("Five", "Harry");       hash.Add("Six", "F");       hash.Add("Seven", "Tom");       hash.Add("Eight", "Andy");       hash.Add("Nine", "I");       hash.Add("Ten", "Tim");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry entry in hash) { ... Read More

Removing the specified element from the List in C#

AmitDiwan
Updated on 06-Dec-2019 10:00:23

137 Views

To remove the specified element from the list, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list1 = new List();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");       list1.Add("Four");       list1.Add("Five");       Console.WriteLine("Elements in List1...");       foreach (string res in list1) {          Console.WriteLine(res);       }       List list2 = new List();       list2.Add("India");       list2.Add("US");       ... Read More

Remove the first occurrence of a specific object from the ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 09:55:19

354 Views

To remove the first occurrence of a specific object from the ArrayList, the code is as follows −Exampleusing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("A");       list1.Add("B");       list1.Add("C");       list1.Add("D");       list1.Add("E");       list1.Add("F");       list1.Add("G");       list1.Add("H");       list1.Add("I");       Console.WriteLine("Elements in ArrayList1...");       foreach (string res in list1) {          Console.WriteLine(res);       } ... Read More

Check if a SortedList is read-only in C#

AmitDiwan
Updated on 06-Dec-2019 09:48:45

105 Views

To check if a SortedList is read-only, 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("One", "IT");       list.Add("Two ", "Operations");       list.Add("Three", "Marketing");       list.Add("Four", "Purchase");       list.Add("Five", "Sales");       list.Add("Six", "Finance");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list) {          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("List of values...SortedList"); ... Read More

Getting the keys in a SortedList object C#

AmitDiwan
Updated on 06-Dec-2019 09:43:10

102 Views

To get the keys in 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("One", "Finance");       list.Add("Two", "Marketing");       list.Add("Three", "Sales");       list.Add("Four", "Purchase");       list.Add("Five", "Operations");       list.Add("Six", "IT");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list) {          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Index at key ... Read More

Advertisements