C # and Java comparative study: data types, collections, stacks and queues, Diego da, variable parameters, enumerated

type of data:

  C#:String与StringBuilder

Java:String与StringBuffer


The first string is not used in the first letter should be capitalized.

The second is not used to have written int Integer, though you can define int i = 0, but for other generic usage must ArrayList <Integer>.

Comparative common collections:

 

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

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

                                   Set (including: HashSet <T>, SoredSet <T>)


Set: can not contain duplicate elements;

List: may contain duplicate elements. 

 

Or with a lot of class collections, the comparison I have a big head almost, and finally find such a simple relationship. 

Stack and Queue:

C#  :Stack<T>  Queue<T>

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


Stack consistent usage, usage and Queue Name substantially days and the difference, the answer in detail below. 

Java Queue C # method names and different:

Java Queue related methods:

add                increased one yuan cable                                         if the queue is full, an exception is thrown a IIIegaISlabEepeplian
Remove      removes and returns the element head of the queue       if the queue is empty, throw an exception NoSuchElementException
element   returns the element head of the queue                         if the queue is empty, an exception is thrown a NoSuchElementException
offer              add an element and returns true              if the queue is full, false returns
poll                  removed and returned to ask the head of the queue element        if the queue is empty, null is returned
peek              returns the element head of the queue                         if the queue is empty , null is returned
put                  add an element                                           if the queue is full, then blocked

take         to remove and return the head of the queue element      if the queue is empty, blocked

 

A more detailed article reference links: http://www.cnblogs.com/end/archive/2012/10/25/2738493.html 

 

Iterator syntax:

# C: the foreach (Object in objList O) interface name} {iterative implementation of: the IEnumerable

Java: the foreach (Object O: objList) {}    interface name iterative implementation of:  the Iterable

 

variable parameter:

 # C: void the Sum (params int [] List)} to {params keywords 

 The Java: void SUM (int ... List) {} with "..." three points for the keyword

 

Enumeration, Java enum can play out the pattern:

  C #: enum can only set the constant value

  Java: In addition to setting the constant value and the same C #, Java still retains the basic functions of a special class, allowing players to play their own; and C # to do special restrictions.

 

C # and Java string and turn enumerate enumeration traversal difference:

C # conversion codes:

     public   class  the Test
    {
         protected   void  Method, ()
        {
            A = A (A) that Enum.Parse ( typeof (A),  " B " ); // Enumeration conversion
      foreach (string enumName in Enum.GetNames(typeof(A)))
            {
// enumeration traversal
            }

        }

        public enum A
        {
            b,
            c
        }
    }

 

Java conversion codes:

 
    public  class Test
    {
         protected  void method()
        {
            A a = A.valueOf("b");
      for (A a : A.values())
            {
// enumeration traversal
            }
        }

         public  enum A
        {
            b,
            c
        }
     }

 

Basically the same, today to see the content, basically so much, so I wrote here, such a point of content, relatively light finish, it took several hours, really sad reminders.

 

Reproduced in: https: //my.oschina.net/secyaher/blog/274283

Guess you like

Origin blog.csdn.net/weixin_33898876/article/details/91966954