Length (set)

From SwiftAPI

Jump to: navigation, search

Contents

C++

#include <set>
#include <string>
using namespace std;
 
set<string> s;
s.insert("foo");
s.insert("bar");
int n = s.size();
// n == 2

Java

Set<String> s = new HashSet<String>();
s.add("foo");
s.add("bar");
int n = s.size();
// n == 2

Objective-C

developer.apple.com

@property(readonly) NSUInteger count
NSSet *s = [NSSet setWithObjects:@"foo", @"bar", nil];
int n = s.count;
// n == 2

Python

docs.python.org

s = set()
s.add('foo')
s.add('bar')
n = len(s)
# n == 2

Ruby

Ruby-Doc.org

require 'set'
 
s = Set.new
s << 'foo'
s << 'bar'
n = s.length
# n == 2

Swift

let s : Set<String> = ["foo", "bar"]
let n = s.count
// n == 2
Personal tools