Passing Autumn

The same 3 years, and some people from students to as the MVP, and I was in place, then the code to show off the autumn wind, a little sad, a little cool!

Bulletin
Content is very powerful ~ ~ ~ ~ ~ ~ Do not look outside the invasion not as sharp and brother, I felt kind of sense of loss ~ ~ ~

C#与Java对比学习:数据类型、集合类、栈与队列

数据类型:

  C#:String与StringBuilder

Java:String与StringBuffer


第一个不习惯是string的第一个字母必须大写了。

第二个不习惯是int得写成Integer了,虽然可以定义int i=0,但是对于泛型等用法必须ArrayList<Integer>。


常用集合类比较:

 

C#  :HashTable         List<T>                                                                Dictionary<T,K>  

Java:HashTable         List(包括:ArrayList<T>,LinkedList<T>)             Map<T,K>(包括:HashMap<T,K>,SortedMap<T,K>)

                                   Set(包括:HashSet<T>,   SoredSet<T>)


Set:不能包含重复的元素;

List:可以包含重复的元素。 

 

集合的类还是挺多的,比较的我头差点都大了,最后才找出这种简单的对应关系。 


Stack和Queue

C#  :Stack<T>  Queue<T>

Java:Stack<T>   Queue(包括四个:LinkedBlockingQueue<T>、ArrayBlockingQueue<T>、PriorityBlockingQueue<T>、DelayQueue<T>)


Statck用法基本一致,Queue用法与名称基本上差天与地,下面有详细解答。 


Java Queue方法名称和C#不同:

Java Queue 的相关方法:

add        增加一个元索                     如果队列已满,则抛出一个IIIegaISlabEepeplian异常
remove   移除并返回队列头部的元素    如果队列为空,则抛出一个NoSuchElementException异常
element  返回队列头部的元素             如果队列为空,则抛出一个NoSuchElementException异常
offer       添加一个元素并返回true       如果队列已满,则返回false
poll         移除并返问队列头部的元素    如果队列为空,则返回null
peek       返回队列头部的元素             如果队列为空,则返回null
put         添加一个元素                      如果队列满,则阻塞

take        移除并返回队列头部的元素     如果队列为空,则阻塞

 

更详细的参考文章链接:http://www.cnblogs.com/end/archive/2012/10/25/2738493.html 


 

迭代语法:

C#  :foreach(object o in objList){}  实现迭代的接口名称为:IEnumerable

Java:foreach(object o : objList){}   实现迭代的接口名称为: Iterable

 

基本上一致,今天看的内容,基本就这么多了,所以就写到这里了,这么点内容,光比较整理,花了好几个小时,真悲催。

 

Autumn Park is QBlog the official site, created by the passing autumn, based on the framework data layers developed cyqdata support multi-user, multi-language, multi-database (access, mssql, oracle), directory level url and other powerful blog system
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"

2013/7/30 1:16:20 | Other | |

  • Post Comment