`

java for in

    博客分类:
  • java
 
阅读更多

这是JDK1.5的新特性泛型的for循环
效果等同,那个更简单?
第二个for循环在编译的时候会强直检查list中的对象类型是否是UserBean类型,如果不是会报编译错误
第一个for循环编译没有问题,会在运行的时候报错
相比之下第二种方法对于程序的稳定性更有利,而且不用显示的类型转换,提升了软件性能,泛型编程也是JAVA提倡的
for(int loop=0;loop<list.size();loop++){
           UserBean bean = (UserBean )list.get(loop); //显示的类型转换
           System.out.println(UserBean .getName());
}

for(UserBean bean : list){
         System.out.println(bean.getName());
}
分享到:
评论

相关推荐

    Thinking in C: Foundations for Java &amp; C++

    Thinking in C: Foundations for Java & C++ by Chuck Allison produced by Bruce Eckel Chapter 1: Introduction and Getting Started40 MinutesStart Lecture Chapter 2: Fundamental Data Types41 ...

    Java增强的for循环

    * 虽然forin循环会被编译器转化为Iterator操作,但是使用forin时,Iterator是不可见的,所以如果需要调用Iterator.remove()方法,或其他一些操作,forin循环就有些力不从心了。 Java增强的for循环可以使代码更加...

    Mastering Java for Data Science

    Java is the most popular programming language, according to the TIOBE index, and it is a very typical choice for running production systems in many companies, both in the startup world and among large...

    Core Java for the Impatient

    Given the size of the language and the scope of the new features introduced in Java SE 8, there’s plenty of material to cover, but it’s presented in small chunks organized for quick access and easy...

    Java for Data Science

    Java for Data Science English | 6 Feb. 2017 | ISBN: 1785280112 Key Features Your entry ticket to the world of data science with the stability and power of Java Explore, analyse, and visualize your ...

    Java for the Web with Servlets,JSP,and EJB,A Developer's Guide to J2EE Solutions

    In addition to excellent content, this book includes licenses to two Java web components from BrainySoftware.com. You receive a full license of the Programmable File Download component for commercial ...

    JAVA使用ElasticSearch查询in和not in的实现方式

    JAVA使用ElasticSearch查询in和not in的实现方式 Elasticsearch是一个基于Lucene的搜索服务器,提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。它是用Java开发的,并作为Apache许可条款下的开放...

    Java Reflection in Action

    Java Reflection in Action is unique in presenting a clear account of all the cool things you can do with reflection, and at the same time pro- viding the sound conceptual basis that developers need to...

    Java Concurrency in Practice JAVA并发编程实践(中英文版)

    Using the concurrency building blocks in java.util.concurrent Performance optimization dos and don'ts Testing concurrent programs Advanced topics such as atomic variables, nonblocking algorithms, ...

    java reflection in action

    1. **Class类**:每个Java类在运行时都有一个与之对应的Class对象,可以通过`Class.forName()`或对象的`getClass()`方法获取。Class对象提供了获取类信息的方法,如类名、包名、父类、接口、枚举常量等。 2. **...

    Doug Lowe-Java All-in-One for Dummies-Wiley (2017)

    《Java All-in-One for Dummies》是由Doug Lowe撰写的一本Java编程语言教程书籍,由Wiley出版社出版。本书第五版详细介绍了Java编程的各个方面,适合初学者和希望巩固Java知识的专业人士。在众多版本中,第五版是...

    Programming Finite Elements in Java

    Programming Finite Elements in Java™ teaches the reader FEM algorithms and their programming in Java™ through a single finite element Java™ program. The compact, simple code makes it straight...

    Java_for_the_Web_with_Servlets

    "Java for the Web with Servlets, JSP, and EJB: A Developer’s Guide to J2EE Solutions" by Budi Kurniawan is a comprehensive guide aimed at helping developers master web programming in Java. The book ...

    Java for Programmers

    Written for programmers with a background in high-level language programming, this book applies the Deitel signature live-code approach to teaching programming and explores the Java language and Java ...

    Manning Java Reflection In Action

    Java Reflection in Action is unique in presenting a clear account of all the cool things you can do with reflection, and at the same time providing the sound conceptual basis that developers need to ...

    Learn Java for Android Development 3rd Edition mobi格式

    Learn Java for Android Development, Third Edition, is an update of a strong selling book that now includes a primer on Android app development (in Chapter 1 and Appendix C, which is distributed in the...

    Java in easy steps: Covers Java 9, 6th Edition - epub格式

    Java in easy steps, 6th edition instructs you how to easily create your own exciting Java programs. Updated for Java 9, which was released September 2017, it contains separate chapters on the major ...

Global site tag (gtag.js) - Google Analytics