Java EE Fundamentals (16)/collections

Source: Internet
Author: User

1. Set Frame (remove repeating string elements in ArrayList)
  • A: Case Demo

    • Requirement: ArrayList removes duplicate values of strings in the collection (the contents of the string are the same)
    • Idea: Create a new collection method

       /** * A: Case Demo * Requirements: ArrayList remove duplicate values of strings in the collection (the contents of the string are the same) * idea: Create a new collection mode */public static void Main (string[] args) {A    Rraylist list = new ArrayList ();    List.add ("a");    List.add ("a");    List.add ("B");    List.add ("B");    List.add ("B");    List.add ("C");    List.add ("C");    List.add ("C");    List.add ("C");    SYSTEM.OUT.PRINTLN (list);    ArrayList newlist = getsingle (list); System.out.println (newlist);} /* * Remove Duplicates * 1, return ArrayList * 2, parameter list ArrayList */public static ArrayList getsingle (ArrayList list) {ArrayList NewList = n            EW ArrayList ();                  Create a new collection Iterator it = List.iterator ();            Gets the iterator while (It.hasnext ()) {//Determines whether there is an element in the old collection, String temp = (string) it.next ();                      Temporarily record each element in the IF (!newlist.contains (temp)) {//If the new collection does not contain the element Newlist.add (temp);                                 Add the element to the new collection}} return newlist; Returns the new collection}  
2. Set FRAME (remove duplicate custom object elements in ArrayList)
    • A: Case Demo
      • Requirement: ArrayList removes duplicate values for custom object elements in the collection (the object has the same member variable value)
    • B: Precautions
      • Overriding the Equals () method
3. Set FRAME (unique function of LinkedList)
    • A:linkedlist class overview
    • B:linkedlist Class-specific features
      • public void AddFirst (e e) and AddLast (e e)
      • Public E GetFirst () and GetLast ()
      • Public e Removefirst () and public e removelast ()
      • Public E get (int index);
4. Collection framework (Stack and queue data structure)
    • Stack
      • Advanced Post-out
    • Queue
      • Advanced First Out
5, set framework (using LinkedList to simulate the collection of stack data structure and test)
    • A: Case Demo

      • Requirements: Use LinkedList to simulate the collection of stack data structures and test
      • Create a class to encapsulate the methods in linked
      • public class Stack {    private LinkedList list = new LinkedList();     //创建LinkedList对象    public void in(Object obj) {        list.addLast(obj);                          //封装addLast()方法    }    public Object out() {        return list.removeLast();                   //封装removeLast()方法    }    public boolean isEmpty() {        return list.isEmpty();                      //封装isEmpty()方法    }}
6. Collection Framework (Generic overview and basic usage)
    • A: Generic Overview
    • B: Generic Benefits
      • Increased security (converting run-time errors to compile time)
      • Save the trouble of a strong turn
    • C: Generic Basic use
      • The <> must be a reference data type
    • D: Generic Usage considerations
      • Pre-and post-generics must be consistent, or the following generics can be omitted without writing (1.7 new feature diamond-shaped generics)
7. Collection Framework (ArrayList store strings and custom objects and traverse the generic version)
    • A: Case Demo
      • ArrayList storing strings and traversing the generic version
8. Set FRAME (the origin of generics)
    • A: Case Demo
      • The origin of generics: the introduction of the problem through object transformation
      • Early object types can receive arbitrary types of objects, but in actual use there is a problem with type conversions. There is a hidden problem, so Java provides generics to address this security issue.
9, set framework (generic class overview and use)
    • A: Generic class overview
      • To define a generic type on a class
    • B: Define the format
      • public class class name < generic type 1,... >
    • C: Precautions
      • Generic type must be a reference type
    • D: Case Demo
      • Use of generic classes
10. Collection Framework (Overview and use of generic methods)
    • A: Overview of generic methods
      • Define generics on a method
    • B: Define the format
      • Public < generic type > return type method name (generic type variable name)
    • C: Case Demo
      • Use of generic methods
11. Collection Framework (Overview and use of generic interfaces)
    • A: Generic interface Overview
      • To define generics on an interface
    • B: Define the format
      • Public interface interface name < generic type >
    • C: Case Demo
      • Use of generic interfaces
12. Set FRAME (generic high-level wildcard character)
    • A: Generic wildcard characters <?>
      • Any type, if not explicitly, is object and any Java class.
    • B:? Extends E
      • Down qualification, E and its subclasses
    • C:? Super E
      • Limit up, E and its parent class
13. Collection Framework (Enhanced for overview and use)
    • A: Enhanced for overview
      • Simplifying the traversal of arrays and collection collections
    • B: Format:
    • for(元素数据类型 变量 : 数组或者Collection集合) {    使用变量即可,该变量就是元素}
    • C: Case Demo
      • Arrays, collection storage elements with enhanced for traversal
    • D: Benefits
      • Simplifying traversal
14. Collection Framework (ArrayList store strings and custom objects and traverse enhanced for version)
    • A: Case Demo

      • ArrayList storing strings and traversing enhanced for version
      • ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");list.add("d");for(String s : list) {    System.out.println(s);}
15, set frame (three kinds of iterations can be deleted)
    • Normal for loop, can be deleted, but index to--
    • Iterators, which can be deleted, but must use the Remove method of the iterator itself, or a concurrency modification exception will occur
    • Enhanced for loop cannot be deleted
16. Collection Framework (overview and use of static import)
    • A: Static Import Overview
    • B: Format:
      • Import static package name .... class name. method name;
      • Levels that can be imported directly to a method
    • C: Precautions
      • The method must be static, and if there are multiple static methods with the same name, it is easy to know who to use. This time, you must prefix it. This shows that the meaning is not big, so generally not, but to be able to read.
17. Set Frame (overview and use of variable parameters)
    • A: Overview of variable parameters
      • When defining a method, you do not know how many parameters to define
    • B: Format
      • Modifier returns a value type method name (data type ... Variable name) {}
    • C: Precautions:
      • The variable here is actually an array
      • If a method has a variable parameter, and there are multiple parameters, then the variable parameter is definitely the last
18. Collection Framework (use of the Aslist () method of the Arrays tool class)
    • A: Case Demo
      • Use of the Aslist () method of the Arrays tool class
      • Collection ToArray (t[] a) generic version of the set-to-go array
19, set FRAME (set nested arraylist nested ArrayList)
    • A: Case Demo
      • Nesting nested arraylist arraylist nested sets

Java EE Fundamentals (16)/collections

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.