• JAVA Collections常用方法


    1. /* 
    2.     集合框架的工具类 
    3.  
    4.     Collections: 
    5. */  
    6.   
    7. import java.util.*;  
    8.   
    9. class Test  
    10. {  
    11.   
    12.     public static void main(String [] args)  
    13.     {  
    14.         List<String> ls = new ArrayList<String>();  
    15.           
    16.         ls.add("aaa");  
    17.         ls.add("afs");  
    18.         ls.add("fds");  
    19.         ls.add("bcd");  
    20.   
    21.         sop(ls);  
    22.   
    23.         Collections.sort(ls);  
    24.       
    25.         sop(ls);  
    26.   
    27.         String tmp = Collections.max(ls);  
    28.         sop("max :"+tmp);  
    29.   
    30.         int index = Collections.binarySearch(ls,"bcd");  
    31.         sop("index :" + index);  
    32.         int index2 = Collections.binarySearch(ls,"bcde");  
    33.         sop("index2 :" + index2);  
    34.         //如果搜索键包含在列表中,则返回搜索键的索引;否则返回 (-(插入点) - 1)  
    35.       
    36.         //替换   
    37.         Collections.replaceAll(ls, "afs","KK");  
    38.         sop(ls);  
    39.   
    40.         //反转,逆置  
    41.         Collections.reverse(ls);  
    42.         sop(ls);  
    43.   
    44.           
    45.         //fill 方法可以将list集合中所有元素转换成指定元素  
    46.         Collections.fill(ls,"pp");  
    47.         sop(ls);  
    48.     }  
    49.   
    50.     public static void sop(Object obj)  
    51.     {  
    52.         System.out.println(obj);  
    53.     }  
    54. }  
  • 相关阅读:
    谷歌脸书第三方登录
    初步了解Owin
    select2去掉搜索框
    angularjs教程——自定义指令
    angularjs教程——Dom操作相关指令详解
    http://172.21.87.57:8081/seeyon/
    nce 1,a puma at large
    股池
    永清环保
    出门需要带的东西
  • 原文地址:https://www.cnblogs.com/dongrilaoxiao/p/6677889.html
Copyright © 2020-2023  润新知