Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between [String] and Array<String>

Tags:

arrays

swift

Which is better way to declare Array and Dictionary, I have used both:

Array<String>

[String]

For me [String] is very fast in terms of coding but in reality how both are different in terms of compiler and performance and which one we should follow?

like image 378
hardikdevios Avatar asked Dec 12 '15 13:12

hardikdevios


People also ask

What is the difference between string and string array in C?

The main difference between Array and String is that an Array is a data structure that stores a set of elements of the same data type while a String is a set of characters. Programming languages such as C supports arrays and strings.

What is array & string?

In programming, an array is a collection of the homogeneous types of data stored in a consecutive memory location and each data can be accessed using its index. In the Java programming language, we have a String data type. The string is nothing but an object representing a sequence of char values.

What is difference between string and array in PHP?

The main difference between an array and a string is that an array is a data structure, while a string is an object. Arrays can hold any data types, while strings hold only char data types. Arrays are mutable, while strings are not. Arrays have a fixed length, while strings do not.


2 Answers

From iOS Developer Library on Swift...

The type of a Swift array is written in full as Array< Element >, where Element is the type of values the array is allowed to store. You can also write the type of an array in shorthand form as [Element]. Although the two forms are functionally identical, the shorthand form is preferred and is used throughout this guide when referring to the type of an array.

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html

like image 69
Robert Byrne Avatar answered Sep 28 '22 00:09

Robert Byrne


The two are equivalent.

From Apple

Array Type Shorthand Syntax

The type of a Swift array is written in full as Array, where Element is the type of values the array is allowed to store. You can also write the type of an array in shorthand form as [Element]. Although the two forms are functionally identical, the shorthand form is preferred and is used throughout this guide when referring to the type of an array.

like image 44
Peter Hornsby Avatar answered Sep 27 '22 23:09

Peter Hornsby