Contains (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");
bool a = s.count("foo") != 0;
bool b = s.count("test") != 0;
// a == true
// b == false

Java

docs.oracle.com

import java.util.*;
 
Set<String> s = new HashSet<String>(Arrays.asList("foo", "bar"));
 
boolean a = s.contains("foo");
boolean b = s.contains("test");
// a == true
// b == false

Objective-C

developer.apple.com

- (BOOL)containsObject:(id)anObject
NSSet *s = [NSSet setWithObjects:@"foo", @"bar", nil];
BOOL a = [s containsObject:@"foo"];
BOOL b = [s containsObject:@"test"];
// a == YES
// b == NO

Python

s = set(["foo", "bar"])
a = "foo" in s
b = "test" in s
# a == True
# b == False

Ruby

Ruby-Doc.org

require 'set'
 
s = Set.new(['foo', 'bar'])
a = s.include?('foo')
b = s.include?('test')
# a == true
# b == false

Swift

let s : Set<String> = ["foo", "bar"]
let a = s.contains("foo")
let b = s.contains("test")
// a == true
// b == false
Personal tools