public static void main(String[] args) {
Stack stack=null;
System.out.println("1、"+stack.empty());
stack=new Stack();
System.out.println("2、"+stack.empty());
}

运行结果:stack没有指向对象

Exception in thread "main" java.lang.NullPointerException
at main.main(main.java:6)

注释掉System.out.println("1、"+stack.empty());运行结束是:true

总结:使用stack的empty()时,首先要给stack初始化

stack的empty()的更多相关文章

  1. stack.isEmpty()和empty()

    public class Stack<E> extends Vector<E> 可以看到Stack类继承了Vector类 这个是stack类里面的方法: /** * Tests ...

  2. [LeetCode] Implement Stack using Queues 用队列来实现栈

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  3. 【DS】About Stack

    栈 一言以蔽之,就是后进的先出(LIFO). C语言实现代码: #include<stdio.h> #include<stdlib.h> typedef struct Stac ...

  4. [C++][数据结构]栈(stack)的实现

    对于栈的定义,前人之述备矣. 我实现的是一个stack<value>容器类,支持push,pop,top,size,empty,clear和copy construction操作. 主要的 ...

  5. Java for LeetCode 225 Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  6. 纸上谈兵:栈(stack)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 栈(stack)是简单的数据结构,但在计算机中使用广泛.它是有序的元素集合.栈最显 ...

  7. java1.7集合源码阅读: Stack

    Stack类也是List接口的一种实现,也是一个有着非常长历史的实现,从jdk1.0开始就有了这个实现. Stack是一种基于后进先出队列的实现(last-in-first-out (LIFO)),实 ...

  8. Leetcode 225 Implement Stack using Queues STL

    用两个队列去实现栈,这里我使用了队列数组q[2],在所有的过程中保证一个队列是空的 push时插入到空的队列中,然后将队列中的元素移到另一个队列中 pop时从不空的队列中pop() peek时从不空的 ...

  9. Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

随机推荐

  1. ruby技巧001:求md5散列

    ruby核心库中未包含md5之类的功能,不过在其标准库digest中可以方便的使用该功能: = Digest (from ruby core) ---------------------------- ...

  2. ruby中如何调用与局部变量同名的私有方法

    如果ruby中一个局部变量名和私有方法名同名的话,默认该名称被解释为变量而不是方法: x=10; def x;puts "what?" end 当你输入x实际不能执行x方法.解释器 ...

  3. 基于event 实现的线程安全的优先队列(python实现)

    event 事件是个很不错的线程同步,以及线程通信的机制,在python的许多源代码中都基于event实现了很多的线程安全,支持并发,线程通信的库 对于优先队列的堆实现,请看<python下实现 ...

  4. 多线程编程 NSOperation

     前言 1.NSThread的使用,虽然也可以实现多线程编程,但是需要我们去管理线程的生命周期,还要考虑线程同步.加锁问题,造成一些性能上的开销.我们也可以配合使用NSOperation和NSOper ...

  5. javax.mail

    摘抄 example: public static void sendEmail(ConfBean cBean, String filename, String filepath) { try { P ...

  6. MDF,了解一下

    1.MDF定义 MDF,全称(Measurement Data Format),即测量数据格式,是ASAM(自动化及测量系统标准协会)定义的.MDF的网页https://www.asam.net/st ...

  7. VS 和 VAssistX 常用快捷键

    ----------------------------------------------------------------函数跳转-------------------------------- ...

  8. SDL相关资料

    SDL(Simple DirectMedia Layer)是一个自由的跨平台的多媒体开发包,适用于 游戏.游戏SDK.演示软件.模拟器.MPEG播放器和其他应用软件.目前支持windows,linux ...

  9. Using SSH and SFTP in Mac OS X

    http://answers.stat.ucla.edu/groups/answers/wiki/7a848/ SH and SFTP are command line applications av ...

  10. java接受安卓及ios App上传的图片,并保存到阿里OSS

    做后台的时候,写了两个方法,分别用来获取安卓和苹果IOS端上传的头像,保存到阿里云OSS图片存储服务器上.(SMM框架) 安卓及H5版本: /** * 上传用户头像 */ @RequestMappin ...