Skip to content
- Tutorials
- Python Tutorial
- Taking Input in Python
- Python Operators
- Python Data Types
- Python Loops and Control Flow
- Python Functions
- Python OOPS Concept
- Python Data Structures
- Python Exception Handling
- Python File Handling
- Python Exercises
- Java
- Java Programming Language
- Java Collections
- Java 8 Tutorial
- Java Programs
- Java Interview Questions
- Java Exercises
- Java Quiz
- Java Projects
- Advance Java
- Programming Languages
- System Design
- Interview Corner
- Computer Science Subjects
- DevOps
- Linux
- Software Testing
- Databases
- Android
- Excel
- Mathematics
- Python Tutorial
- DSA
- Data Structures
- Algorithms
- Analysis of Algorithms
- Searching Algorithms
- Sorting Algorithms
- Greedy Algorithms
- Dynamic Programming
- Graph Algorithms
- Pattern Searching
- Recursion
- Backtracking
- Divide and Conquer
- Mathematical Algorithms
- Geometric Algorithms
- Bitwise Algorithms
- Randomized Algorithms
- Branch and Bound
- Algorithms Tutorial
- DSA Tutorial
- Practice
- All DSA Problems
- Problem of the Day
- Company Wise Coding Practice
- GfG SDE Sheet
- Practice Problems Difficulty Wise
- Language Wise Coding Practice
- Curated DSA Lists
- Competitive Programming
- Company Wise SDE Sheets
- DSA Cheat Sheets
- Top Interview Questions
- Puzzles
- Data Science
- Web Tech
- Courses
-
Last Updated : 06 Sep, 2021
Comments
Improve
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.ContainsValue(Object) method is used to check whether a SortedList object contains a specific value or not.
Properties:
- A SortedList element can be accessed by its key or by its index.
- A SortedList object internally maintains two arrays to store the elements of the list, i.e, one array for the keys and another array for the associated values.
- A key cannot be null, but a value can be.
- The capacity of a SortedList object is the number of elements the SortedList can hold.
- A SortedList does not allow duplicate keys.
- Operations on a SortedList object tend to be slower than operations on a Hashtable object because of the sorting.
- Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.
Syntax :
public virtual bool ContainsValue (object value);
Here, value is the value to locate in the SortedList object and it can be null.
Return Value: This method returns True if the SortedList object contains an element with the specified value, otherwise it returns False.
Below programs illustrate the use of SortedList.ContainsValue(Object) Method:
Example 1:CSHARP
// C# code to check if a SortedList
// object contains a specific value
using
System;
using
System.Collections;
class
GFG {
// Driver code
public
static
void
Main()
{
// Creating an SortedList
SortedList mySortedList =
new
SortedList();
// Adding elements to SortedList
See AlsoHow to Get Value from HashTable Collection in C# using Specified KeyHow to check if a hash contains a particular key in RubyC# | Strings | .Contains() | CodecademyHow to determine if a value exists in a linked list in C#mySortedList.Add(
"1"
,
"1st"
);
mySortedList.Add(
"2"
,
"2nd"
);
mySortedList.Add(
"3"
,
"3rd"
);
mySortedList.Add(
"4"
,
"4th"
);
// Checking if a SortedList object
// contains a specific value
Console.WriteLine(mySortedList.ContainsValue(
null
));
}
}
Output:
False
Example 2:
CSHARP
// C# code to check if a SortedList
// object contains a specific value
using
System;
using
System.Collections;
class
GFG {
// Driver code
public
static
void
Main()
{
// Creating an SortedList
SortedList mySortedList =
new
SortedList();
// Adding elements to SortedList
mySortedList.Add(
"h"
,
"Hello"
);
mySortedList.Add(
"g"
,
"Geeks"
);
mySortedList.Add(
"f"
,
"For"
);
mySortedList.Add(
"n"
,
"Noida"
);
// Checking if a SortedList object
// contains a specific value
Console.WriteLine(mySortedList.ContainsValue(
"Geeks"
));
}
}
Output:
True
Note:
- The values of the elements of the SortedList object are compared to the specified value using the Equals method.
- This method performs a linear search, therefore, the average execution time is proportional to Count, i.e, this method is an O(n) operation, where n is Count.
Reference:
Similar Reads
C# | Check whether a SortedList object contains a specific key
SortedList.Contains(Object) Method is used to check whether a SortedList object contains a specific key. Syntax: public virtual bool Contains (object key); Here, key is the Key which is to be located in the SortedList object. Return Value: This method returns the true if the SortedList object contains an element with the specified key otherwise, it
2 min read
C# | Replacing the value at a specific index in a SortedList object
SortedList.SetByIndex(Int32, Object) Method is used to replace the value at a specific index in a SortedList object. Syntax: public virtual void SetByIndex (int index, object value); Parameters: index: It is the zero-based index at which to save value. value: It is the Object to save into the SortedList object. The value can be null. Exception: Thi
3 min read
C# | Getting the value at the specified index of a SortedList object
SortedList.GetByIndex(Int32) Method is used to get the value at the specified index of a SortedList object. Syntax: public virtual object GetByIndex (int index); Here index is the zero-based index of the value to get. Return Value: It returns the value at the specified index of the SortedList object. Exception: This method will throw ArgumentOutOfR
2 min read
C# | Getting index of the specified value in a SortedList object
SortedList.IndexOfValue(Object) Method is used to get the zero-based index of the first occurrence of the specified value in a SortedList object. Syntax: public virtual int IndexOfValue (object value); Here, value is the Value which is to be located in the SortedList object. The value can be null. Return Value: This method return the zero-based ind
3 min read
C# | Check if a SortedList object is synchronized
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.IsSynchronized property is used to get a value indicating whether access to a SortedList object is synchronized (threa
2 min read
C# | Check if a SortedList object has a fixed size
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.IsFixedSize property is used to check whether a SortedList object has a fixed size or not. Properties of SortedList: I
2 min read
C# | Creating a synchronized (thread-safe) wrapper for a SortedList object
SortedList.Synchronized(SortedList) Method is used to get the synchronized (thread-safe) wrapper for a SortedList object. Syntax: public static System.Collections.SortedList Synchronized (System.Collections.SortedList list); Here, list is the name of the SortedList object which is to be synchronized. Exception: This method will throw ArgumentNullEx
2 min read
C# | Search in a SortedList object
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.ContainsKey(Object) method is used to check whether a SortedList object contains a specific key or not. Properties: A
3 min read
C# | Getting the keys in a SortedList object
SortedList.Keys Property is used to get the keys in a SortedList object. Syntax: public virtual System.Collections.ICollection Keys { get; } Property Value: An ICollection object containing the keys in the SortedList object. Below programs illustrate the use of above-discussed property: Example 1: // C# code to get an ICollection containing // the
2 min read
C# | Getting the Values in a SortedList object
SortedList.Values Property is used to get the values in a SortedList object. Syntax: public virtual System.Collections.ICollection Values { get; } Property Value: An ICollection object containing the values in the SortedList object. Below programs illustrate the use of above-discussed property: Example 1: // C# code to get an ICollection containing
2 min read
C# | Copying the SortedList elements to an Array Object
SortedList.CopyTo(Array, Int32) Method is used to copy SortedList elements to a one-dimensional Array object, starting at the specified index in the array. Syntax: public virtual void CopyTo (Array array, int arrayIndex); Parameters: array: It is the one-dimensional Array object that is the destination of the DictionaryEntry objects copied from Sor
2 min read
C# | Getting the key at the specified index of a SortedList object
SortedList.GetKey(Int32) Method is used to get the key at the specified index of a SortedList object. Syntax: public virtual object GetKey (int index); Here, index is the zero-based index of the key to get. Return Value: This method returns the key at the specified index of the SortedList object. Exception: This method throws ArgumentOutOfRangeExce
2 min read
C# | Getting the list of Values of a SortedList object
SortedList.GetValueList Method is used to get the list of keys in a SortedList object. Syntax: public virtual System.Collections.IList GetValueList (); Return Value: It returns an IList object containing the values in the SortedList object. Below programs illustrate the use of above-discussed method: Example 1: // C# code for getting the values //
2 min read
C# | Getting the list of keys of a SortedList object
SortedList.GetKeyList Method is used to get the list of keys in a SortedList object. Syntax: public virtual System.Collections.IList GetKeyList (); Return Value: It returns an IList object containing the keys in the SortedList object. Below programs illustrate the use of above-discussed method: Example 1: // C# code for getting the keys // in a Sor
2 min read
C# | Setting the capacity to the actual number of elements in a SortedList object
SortedList.TrimToSize Method is used to set the capacity to the actual number of elements in a SortedList object.Syntax: public virtual void TrimToSize (); Exception: This method will throw NotSupportedException if the SortedList object is read-only or SortedList has a fixed size.Below programs illustrate the use of above-discussed method:Example 1
3 min read
C# | Getting the index of the specified key in a SortedList object
SortedList.IndexOfKey(Object) Method is used to get the zero-based index of the specified key in a SortedList object. Syntax: public virtual int IndexOfKey (object key); Here, key is the Key which is to be located in the SortedList object. Return Value: This method returns the zero-based index of type System.Int32 of the key parameter if the key is
3 min read
How to create a shallow copy of SortedList Object in C#
SortedList.Clone() Method is used to create a shallow copy of a SortedList object. Syntax: public virtual object Clone(); Return Value: It returns a shallow copy of the SortedList object. The type of returned value will be Object. Note: A shallow copy of a collection copies only the elements of the collection, whether they are reference types or va
3 min read
C# | How to add key/value pairs in SortedList
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.Add(Object, Object) Method is used to add an element with the specified key and value to a SortedList object. Properti
3 min read
C# | Get or set the value associated with specified key in SortedList
SortedList.Item[Object] Property is used to get and set the value associated with a specific key in a SortedList object. Syntax: public virtual object this[object key] { get; set; } Here, the key is associated with the value to get or set. It is of the object type. Return Value: This property returns the value associated with the key parameter in t
4 min read
C# | Check if the Hashtable contains a specific Value
The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.ContainsValue(Object) Method is used to check whether the Hashtable contains a specific value or not. Syntax: public virtual bool ContainsValue(object value); Param
2 min read
C# | Check if the StringDictionary contains a specific value
StringDictionary.ContainsValue(String) method is used to check whether the StringDictionary contains a specific value or not. Syntax: public virtual bool ContainsValue (string value); Here, value is the value to locate in the StringDictionary. The value can be null. Return Value: The method returns true if the StringDictionary contains an element w
2 min read
C# | Check if two SortedList objects are equal
Equals(Object) Method which is inherited from the Object class is used to check whether the specified SortedList object is equal to another SortedList object or not. Syntax: public virtual bool Equals (object obj); Here, obj is the object which is to be compared with the current object. Return Value: This method return true if the specified object
2 min read
C# | Check if a SortedList is read-only
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.IsReadOnly property is used to get a value which indicates that a SortedList object is read-only or not. Properties of
2 min read
Difference between SortedList and SortedDictionary in C#
In C#, SortedList is a collection of key/value pairs which are sorted according to keys. By default, this collection sort the key/value pairs in ascending order. It is of both generic and non-generic type of collection. The generic SortedList is defined in System.Collections.Generic namespace whereas non-generic SortedList is defined under System.C
3 min read
C# | How to create a SortedList
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. Properties of SortedList: Internally the object of SortedList maintains two arrays. The first array is used to store the elements
2 min read
C# | Remove the element with the specified key from a SortedList
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.Remove(Object) method is used to remove the element with the specified key from a SortedList object. Properties: A Sor
3 min read
C# | Remove all elements from a SortedList
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.Clear method is used to remove all the elements from a SortedList object. Properties: A SortedList element can be acce
2 min read
C# | Remove from the specified index of a SortedList
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.RemoveAt(Int32) method is used to remove the element at the specified index of a SortedList object. Properties: A Sort
4 min read
C# | SortedList Class
.math-table { border-collapse: collapse; width: 100%; } .math-table td { border: 1px solid #5fb962; text-align: left !important; padding: 8px; } .math-table th { border: 1px solid #5fb962; padding: 8px; } .math-table tr>th{ background-color: #c6ebd9; vertical-align: middle; } .math-table tr:nth-child(odd) { background-color: #ffffff; } SortedList c
6 min read
C# | Capacity of a SortedList
SortedList.Capacity Property is used to get or set the capacity of a SortedList object. Syntax: public virtual int Capacity { get; set; } Return Value: This property returns the number of elements of type System.Int32 that the SortedList object can contain. Exceptions: ArgumentOutOfRangeException: If the value assigned is less than the current numb
3 min read
Article Tags :
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, check: true }), success:function(result) { jQuery.ajax({ url: writeApiUrl + 'suggestions/auth/' + `${post_id}/`, type: "GET", dataType: 'json', xhrFields: { withCredentials: true }, success: function (result) { $('.spinner-loading-overlay:eq(0)').remove(); var commentArray = result; if(commentArray === null || commentArray.length === 0) { // when no reason is availaible then user will redirected directly make the improvment. // call to api create-improvement-post $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); return; } var improvement_reason_html = ""; for(var comment of commentArray) { // loop creating improvement reason list markup var comment_id = comment['id']; var comment_text = comment['suggestion']; improvement_reason_html += `
${comment_text}
`; } $('.improvement-reasons_wrapper').html(improvement_reason_html); $('.improvement-bottom-btn').html("Create Improvement"); $('.improve-modal--improvement').hide(); $('.improvement-reason-modal').show(); }, error: function(e){ $('.spinner-loading-overlay:eq(0)').remove(); // stop loader when ajax failed; }, }); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ $('.improvement-reason-modal').hide(); } $('.improve-modal--improvement').show(); }); function loadScript(src, callback) { var script = document.createElement('script'); script.src = src; script.onload = callback; document.head.appendChild(script); } function suggestionCall() { var suggest_val = $.trim($("#suggestion-section-textarea").val()); var array_String= suggest_val.split(" ") var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(suggest_val.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `
${suggest_val}
`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-section-textarea').val(""); jQuery('.suggest-bottom-btn').css("display","none"); // Update the modal content const modalSection = document.querySelector('.suggestion-modal-section'); modalSection.innerHTML = `
Thank You!
Your suggestions are valuable to us.
You can now also contribute to the GeeksforGeeks community by creating improvement and help your fellow geeks.
`; }, error:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 5 Words and Maximum Character limit is 2000."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('#suggestion-section-textarea').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // load the captcha script and set the token loadScript('https://www.google.com/recaptcha/api.js?render=6LdMFNUZAAAAAIuRtzg0piOT-qXCbDF-iQiUi9KY',[], function() { setGoogleRecaptcha(); }); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.improvement-reason-modal').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); });