本文整理汇总了Java中gnu.trove.stack.TIntStack.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java TIntStack.toArray方法的具体用法?Java TIntStack.toArray怎么用?Java TIntStack.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.stack.TIntStack
的用法示例。
在下文中一共展示了TIntStack.toArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEquals
import gnu.trove.stack.TIntStack; //导入方法依赖的package包/类
public void testEquals() {
TIntStack stack = new TIntArrayStack();
assertEquals( 0, stack.size() );
stack.push( 10 );
stack.push( 20 );
assertEquals( 2, stack.size() );
TIntStack other = new TIntArrayStack( 20 );
other.push( 10 );
other.push( 20 );
assertEquals( 2, other.size() );
assertTrue( "stacks should equal itself: " + stack,
stack.equals( stack ) );
assertTrue( "stacks should be equal: " + stack + ", " + other,
stack.equals( other ) );
TIntArrayList list = new TIntArrayList( stack.toArray() );
assertFalse( "stack should not equal list: " + stack + ", " + list,
stack.equals( list ) );
}
示例2: testArrays
import gnu.trove.stack.TIntStack; //导入方法依赖的package包/类
public void testArrays() {
int no_entry_value = Integer.MIN_VALUE;
TIntStack stack = new TIntArrayStack(10, no_entry_value);
assertEquals( no_entry_value, stack.getNoEntryValue() );
int[] array;
array = stack.toArray();
assertNotNull( array );
assertEquals( 0, array.length );
stack.push( 10 );
stack.push( 20 );
stack.push( 30 );
stack.push( 40 );
array = stack.toArray();
assertNotNull( array );
assertEquals( 4, array.length );
// NOTE: Top element in stack should be first element in array
assertEquals( 40, array[0] );
assertEquals( 30, array[1] );
assertEquals( 20, array[2] );
assertEquals( 10, array[3] );
assertEquals( 4, stack.size() );
int[] array_correct_size = new int[4];
stack.toArray( array_correct_size );
assertEquals( 40, array_correct_size[0] );
assertEquals( 30, array_correct_size[1] );
assertEquals( 20, array_correct_size[2] );
assertEquals( 10, array_correct_size[3] );
int[] array_too_long = new int[6];
stack.toArray( array_too_long );
assertEquals( 40, array_too_long[0] );
assertEquals( 30, array_too_long[1] );
assertEquals( 20, array_too_long[2] );
assertEquals( 10, array_too_long[3] );
assertEquals( stack.getNoEntryValue(), array_too_long[4] );
int[] array_too_short = new int[2];
stack.toArray( array_too_short );
assertEquals( 40, array_too_short[0] );
assertEquals( 30, array_too_short[1] );
}