Clear (associative array)

From SwiftAPI

Jump to: navigation, search

Contents

C++

msdn

map<string, int> a;
a["test"] = 4;
a["foo"] = 2;
a.clear();
// a.size() == 0

C#

msdn

public System.Collections.Generic.Dictionary : public void Clear ()
using System.Collections.Generic;
 
Dictionary<string, int> a = new Dictionary<string, int>() { { "test", 4 }, { "foo", 2 } };
a.Clear();
// a.Count == 0

Java

J2SE 5.0

import java.util.Hashtable;
 
Hashtable<String, Integer> a = new Hashtable<String, Integer>();
a.put("test", 4);
a.put("foo", 2);
a.clear();
// a.size() == 0

Objective-C

developer.apple.com

- (void)removeAllObjects
NSMutableDictionary *a = [NSMutableDictionary dictionaryWithObjectsAndKeys:@4, @"test",
                                                                           @2, @"foo", nil];
[a removeAllObjects];
// a == {}

Python

a = {'test': 4, 'foo': 2}
a.clear()
# a == {}

Ruby

Ruby-Doc.org

a = {"test" => 4, "foo" => 2}
a.clear
# a == {}

Swift

var a = ["test": 4, "foo": 2]
a.removeAll()
// a == [:]
Personal tools