Ankita Saini has Published 319 Articles

Swift Program to convert the array of characters into the string

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:08:02

510 Views

To convert the array of characters into a string Swift provides the following methods − Using String() initialiser Using append() method Input array = [“S”, “w”, “i”, “f”, “t”] Output Swift Here we join all the characters given in the array to create a string. Method ... Read More

Swift Program to check the given string is empty or not

Ankita Saini

Ankita Saini

Updated on 09-May-2023 10:03:05

1K+ Views

To check if the given string is empty or not Swift provides an inbuilt property named as isEmpty. This property will return true if the given string is empty. And return false if the given string is not empty. Here empty string means whose length is 0 or we can ... Read More

Swift Program to Check if two Dictionaries are equal

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:59:28

317 Views

In Swift, a dictionary is an unordered collection in which data is stored in the form of key-value pairs, where keys are the unique identifiers. So to check the equality of two dictionaries we first need to check if the size of both the dictionaries is equal or not. If ... Read More

Swift Program to check a string starts with a specified substring

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:56:17

886 Views

Swift provides an hasPrefix() function to check if a string starts with a specified substring. The hasPrefix() function returns a boolean value which indicates whether the specified substring matches the starting string characters of the input string. The hasPrefix() function is case sensitive, which means according to this function “a”, ... Read More

Swift Program to check a string end with a specified substring

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:54:35

439 Views

Swift provides an hasSuffix() function to check a string end with a specified substring. The hasSuffix() function returns a boolean value which indicates whether the specified substring matches the ending characters of the input string. The hasSuffix() function is case sensitive that means according to this function “t”, and “T” ... Read More

Swift Program to Add Elements to a Dictionary

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:49:31

75 Views

In Swift, a dictionary is an unordered collection in which data is stored in the form of key-value pairs. To add elements to a dictionary we can use any of the following methods − Using Bracket notation Using updateValue() method Method 1: Using Brackets Notation We can key-value ... Read More

Swift Program to Split a set into Two Halves

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:52:21

135 Views

In Swift, a set is used to create an unordered collection of unique elements. To split a set into two halves we use a approach in which we first determine the midpoint of the given set using integer division method and then loop through the set and insert element ... Read More

Swift Program to sort an array in descending order using selection sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:48:16

394 Views

Selection sort algorithm in swift is a sorting algorithm, in which it select smallest or largest element from the given unsorted array and place that element at the beginning of the unsorted array. This process continue till the last unsorted element. So now we sort an array in descending order ... Read More

Swift Program to sort an array in descending order using bubble sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:46:23

284 Views

Bubble sort algorithm in swift, is the easiest search algorithm. This algorithm sorts the elements by repeatedly swapping adjacent elements if they are not present at the right place. So now we sort an array in descending order using bubble sort. For example − Array - [4, 7, 1, 8] ... Read More

Swift Program to sort an array in ascending order using quick sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:44:58

362 Views

Quick sort algorithm in swift is a sorting algorithm which works on divide and conquer approach. In this sort, we first divide the array into subarrays by selecting a pivot element. Here the division takes place in such a way, in which the smallest elements placed at the left side ... Read More

Previous 1 ... 6 7 8 9 10 ... 32 Next
Advertisements