• 吴裕雄--天生自然java开发常用类库学习笔记:集合工具类Collections


    import java.util.Collections ;
    import java.util.List ;
    import java.util.Set ;
    public class CollectionsDemo01{
        public static void main(String args[]){
            List<String> allList = Collections.emptyList() ;    // 返回空的 List集合
            Set<String> allSet = Collections.emptySet() ;    // 返回空的 List集合
            allList.add("Hello") ;    // 加入数据
        }
    };
    import java.util.Collections ;
    import java.util.List ;
    import java.util.ArrayList ;
    import java.util.Iterator ;
    public class CollectionsDemo02{
        public static void main(String args[]){
            List<String> all = new ArrayList<String>() ;    // 返回空的 List集合
            Collections.addAll(all,"MLDN","LXH","mldnjava") ;
            Iterator<String> iter = all.iterator() ;
            while(iter.hasNext()){
                System.out.print(iter.next() + "、") ;
            }
        }
    };
    import java.util.Collections ;
    import java.util.List ;
    import java.util.ArrayList ;
    import java.util.Iterator ;
    public class CollectionsDemo03{
        public static void main(String args[]){
            List<String> all = new ArrayList<String>() ;    // 返回空的 List集合
            Collections.addAll(all,"MLDN","LXH","mldnjava") ;
            Collections.reverse(all) ;    // 内容反转
            Iterator<String> iter = all.iterator() ;
            while(iter.hasNext()){
                System.out.print(iter.next() + "、") ;
            }
        }
    };
    import java.util.Collections ;
    import java.util.List ;
    import java.util.ArrayList ;
    import java.util.Iterator ;
    public class CollectionsDemo04{
        public static void main(String args[]){
            List<String> all = new ArrayList<String>() ;    // 返回空的 List集合
            Collections.addAll(all,"MLDN","LXH","mldnjava") ;
            int point = Collections.binarySearch(all,"LXH") ;    // 检索数据
            System.out.println("检索结果:" + point) ;
            
        }
    };
    import java.util.Collections ;
    import java.util.List ;
    import java.util.ArrayList ;
    import java.util.Iterator ;
    public class CollectionsDemo05{
        public static void main(String args[]){
            List<String> all = new ArrayList<String>() ;    // 返回空的 List集合
            Collections.addAll(all,"MLDN","LXH","mldnjava") ;
            if(Collections.replaceAll(all,"LXH","李兴华")){// 替换内容
                System.out.println("内容替换成功!") ;
            }
            System.out.print("替换之后的结果:") ;
            System.out.print(all) ;
            
        }
    };
    import java.util.Collections ;
    import java.util.List ;
    import java.util.ArrayList ;
    import java.util.Iterator ;
    public class CollectionsDemo06{
        public static void main(String args[]){
            List<String> all = new ArrayList<String>() ;    // 返回空的 List集合
            Collections.addAll(all,"1、MLDN","2、LXH","3、mldnjava") ;
            Collections.addAll(all,"B、www.mldn.cn") ;
            Collections.addAll(all,"A、www.mldnjava.cn") ;
            System.out.println("排序之前的集合:" + all) ;
            Collections.sort(all) ;
            System.out.println("排序之后的集合:" + all) ;
            
        }
    };
    import java.util.Collections ;
    import java.util.List ;
    import java.util.ArrayList ;
    import java.util.Iterator ;
    public class CollectionsDemo07{
        public static void main(String args[]){
            List<String> all = new ArrayList<String>() ;    // 返回空的 List集合
            Collections.addAll(all,"1、MLDN","2、LXH","3、mldnjava") ;
            System.out.println("交换之前的集合:" + all) ;
            Collections.swap(all,0,2) ;
            System.out.println("交换之后的集合:" + all) ;
            
        }
    };
  • 相关阅读:
    阻塞IO与非阻塞IO
    Java 中 IO 流分为几种?BIO,NIO,AIO 有什么区别?
    linux7启动时自动启动zookeeper和Tomcat
    linux7下配置Tomcat
    背景图片变色,或者背景渐变
    Linux7版本网络配置
    linux7中jdk安装
    linux7中zookeeper的安装-依赖于jdk
    Avoided redundant navigation to current location
    Auto Fix is enabled by default. Use the single string form
  • 原文地址:https://www.cnblogs.com/tszr/p/12152779.html
Copyright © 2020-2023  润新知