AtomicReferenceArray类的length()方法用于返回此AtomicReferenceArray的长度。
用法:
public final int length()
参数:此方法不接受任何内容。
返回值:此方法返回表示此AtomicReferenceArray长度的整数。
以下示例程序旨在说明length()方法:
程序1:
// Java program to demonstrate
// AtomicReferenceArray.length() method
import java.util.concurrent.atomic.*;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference object.
AtomicReferenceArray<Integer> ref
= new AtomicReferenceArray<Integer>(5);
// print the length
int length = ref.length();
System.out.println(
"length of AtomicReferenceArray = "
+ length);
}
}
输出:
length of AtomicReferenceArray = 5
程序2:
// Java program to demonstrate
// AtomicReferenceArray.length() method
import java.util.concurrent.atomic.*;
public class GFG {
public static void main(String[] args)
{
// create a array of Strings
String[] names
= { "AMAN", "AMAR", "SURAJ" };
// create an atomic reference object.
AtomicReferenceArray<String> ref
= new AtomicReferenceArray<String>(names);
// print the length
int length = ref.length();
System.out.println(
"length of AtomicReferenceArray = "
+ length);
}
}
输出:
length of AtomicReferenceArray = 3
相关用法
- Java AtomicReferenceArray set()用法及代码示例
- Java AtomicReferenceArray get()用法及代码示例
- Java AtomicReferenceArray weakCompareAndSetPlain()用法及代码示例
- Java AtomicReferenceArray compareAndExchangeAcquire()用法及代码示例
- Java AtomicReferenceArray getAndSet()用法及代码示例
- Java AtomicReferenceArray lazySet()用法及代码示例
- Java AtomicReferenceArray getOpaque()用法及代码示例
- Java AtomicReferenceArray getPlain()用法及代码示例
- Java AtomicReferenceArray getAcquire()用法及代码示例
- Java AtomicReferenceArray getAndUpdate()用法及代码示例
- Java AtomicReferenceArray updateAndGet()用法及代码示例
- Java AtomicReferenceArray getAndAccumulate()用法及代码示例
- Java AtomicReferenceArray compareAndSet()用法及代码示例
- Java AtomicReferenceArray accumulateAndGet()用法及代码示例
- Java AtomicReferenceArray compareAndExchangeRelease()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 AtomicReferenceArray length() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。