⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readonlyexample.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.collections;

import java.util.*;

/** A class to demonstrate the use of methods
  * to create read-only collections
  */
public class ReadOnlyExample {
   /** Test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      // create a map and intialize it
      SortedMap m1 = new TreeMap();
      m1.put( "beans", new Float( 2.99 ) );
      m1.put( "carrots", new Float( 1.69 ) );
      m1.put( "peas", new Float( 2.19 ) );
      m1.put( "cabbage", new Float( 3.29 ) );
      m1.put( "squash", new Float( 1.89 ) );

      // create a read-only collection, then try to
      // change it
      m1 = Collections.unmodifiableSortedMap( m1 );
      try {
         m1.put( "parsnips", new Float( 1.59 ) );
      } catch ( UnsupportedOperationException x ) {
         System.out.println( x + " caught!" );
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -