zoukankan      html  css  js  c++  java
  • 泛型算法

    前言

      Java也提供了一些封装好了的算法,能对集合数据做处理。

    说明

      Java中的泛型算法不是很多,不如S++中的STL那么多。

      主要也就是排序,查找,以及其他一些很简单的操作。

      本文以排序为例,说明Java中算法的基本使用方法。

    代码示例

     1 package test;
     2 
     3 import java.util.Collections;
     4 import java.util.Iterator;
     5 import java.util.LinkedList;
     6 
     7 /**
     8  * @author   FangMeng
     9  * @version  1.0.0
    10  * @2014-12-09
    11  */
    12 public class Java7Learn {
    13     
    14     public static void main(String[] args) {
    15         
    16         // 构造一个测试的LinkedList集合
    17         LinkedList<String> l = new LinkedList<>();
    18         l.add(new String("1"));
    19         l.add(new String("3"));
    20         l.add(new String("5"));
    21         l.add(new String("2"));
    22         l.add(new String("4"));
    23         l.add(new String("6"));
    24         
    25         Collections.sort(l);
    26         
    27         /*
    28          * 遍历输出结果
    29          */
    30         Iterator<String> i = l.iterator();
    31         while(i.hasNext()){
    32             System.out.println(i.next());
    33         }
    34     }
    35 }

    小结

      1. Java中的算法都比较精巧,实现的是一些很简单的功能。

      2. 当觉得要写一些很“繁琐”但通用的代码的时候,可以查查Java算法手册。

      3. 有部分算法支持"函数对象“参数(不确定Java是不是这么称呼,反正传递进去的一般是一个接口匿名类对象)

  • 相关阅读:
    外感上吐下泻案
    口唇口腔紅肿案
    柴胡桂枝汤---刘渡舟
    肺结核病人外感咳嗽不止案
    下肢麻木案
    老年人全身皮肤瘙痒案
    眩晕案
    頑固头痛失眠案
    PHP 点阵5*7字体
    PHP workerMan tcp与webSocket 透传互通
  • 原文地址:https://www.cnblogs.com/scut-fm/p/4152770.html
Copyright © 2011-2022 走看看