Array Is Empty

From SwiftAPI

Jump to: navigation, search

Contents

C++

msdn

#include <vector>
using namespace std;
 
vector<int> a;
bool b;
 
a = vector<int>();
b = a.empty();
// b == true
 
a = vector<int>();
a.push_back(3);
a.push_back(1);
a.push_back(4);
b = a.empty();
// b == false

C#

using System.Collections.Generic;
 
List<int> a;
bool b;
 
a =  = new List<int>();
b = a.Count == 0;
// b == true
 
a = new List<int>() { 3, 1, 4 };
b = a.Count == 0;
// b == false

Java

J2SE 5.0

import java.util.*;
 
List<Integer> a;
boolean b;
 
a = new ArrayList<Integer>();
b = a.isEmpty();
// b == true
 
a = Arrays.asList(3, 1, 4);
b = a.isEmpty();
// b == false

JavaScript

var a, b;
 
a = [];
b = a.length == 0;
// b == true
 
a = [3, 1, 4];
b = a.length == 0;
// b == false

Perl

Simply use the "not" operator on it. (Empty lists are false.)

@a = ();
$b = !@a;
# $b == 1
 
@a = (3, 1, 4);
$b = !@a;
# $b == ""

PHP

php.net

$a = array();
$b = empty($a);
// $b == true
 
$a = array(3, 1, 4);
$b = empty($a);
// $b == false

Python

Simply use the "not" operator on it. (Empty lists are false.)

a = []
b = not a
# b == True
 
a = [3, 1, 4]
b = not a
# b == False

Ruby

ruby-doc.org

a = []
b = a.empty?
# b == true
 
a = [3, 1, 4]
b = a.empty?
# b == false

Swift

let a : [Int] = []
let b = a.isEmpty
// b == true
 
let a2 = [3, 1, 4]
let b2 = a2.isEmpty
// b2 == false
Personal tools