【java笔记】记一次jdk1.8中List方法removeIf遇到的坑

11 篇文章 0 订阅
导读

经常遇到两个List集合,需要排除其中一个集合中存在的某些元素,比如集合A=【1,2,3,5】,集合B = 【2,3】,如需要排除A在B集合中存在的元素,那么集合结果是【1,5】。
适用场景:比如集合A的分类是某个用户的所有分类,集合B是黑名单分类,那么这时候就需要排除B集合中的分类。

传统方式
        List<Integer> as = Arrays.asList(1, 2, 3, 5);
        List<Integer> bs = Arrays.asList(2, 3);
        List<Integer> result = new ArrayList<>();
        for (Integer _a : as) {
            if(!bs.contains(_a)){
                result.add(_a);
            }
        }
使用1.8中 List removeIf方法
        List<Integer> as = Arrays.asList(1, 2, 3, 5);
        List<Integer> bs = Arrays.asList(2, 3);
        as.removeIf(x-> bs.contains(x));

结果运行发现抛出错误:java.lang.UnsupportedOperationException

原因:是因为Arrays.asList生成的集合ArrayList是一个静态内部类,并且没有重写父类AbstractList的remove方法
1、AbstractList#remove,这种写法就是必须子类重写该方法,如子类使用该方法则抛出该异常。

    public E remove(int index) {
        throw new UnsupportedOperationException();
    }

2、Arrays中静态内部类ArrayList重写方法中没有remove
在这里插入图片描述
3、改造方式:使用重写了remove方法的类,比如ArrayList

    	List<Integer> as =new ArrayList<>(Arrays.asList(1, 2, 3, 5)) ;
        List<Integer> bs = new ArrayList<>(Arrays.asList(2, 3));
        as.removeIf(x-> bs.contains(x));
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Trace File Manager (TFM) - Using PHP and Oracle to manage your distributed trace files--------------------------------------------------------------------------------------Deployment InstructionsOracle Layer The Oracle JServer must be installed and exist in a valid state. Ensure that the directories specified in the parameters for USER_DUMP_DEST and BACKGROUND_DUMP_DEST are set up as utl_file_dir directives in the init.ora, eg utl_file_dir=myDB/oratrace/back utl_file_dir=myDB/oratrace/user Run all of the below mentioned scripts in any database whose trace files you want to view As SYS create a user account (TFMADMIN) See - tfmadmin_create.sql This account will be the repository for all of the Oracle objects used by the utility and will be responsible for retrieving information from the file system for presentation to the PHP layer. nb ! The supplied create script is for demo purposes only. You will need to specify a password and you may also want to assign alternative default and temporary tablespaces. create the external library call Windows - see extWindows.sql Linux - see extLinux.sql nb ! for unix it would be ; create or replace library systemcalls is ‘/lib/libc.so‘; / grant necessary database privileges to tfmadmin tfmAdmin_privs_and_syns.sql grant necessary java privileges to tfmadmin tfmAdmin_java_privs.sql if this fails with any spurious dbms_java errors then issue the statements manually, eg exec dbms_java.grant_permission (‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘,‘your background_dump_dest‘, ‘read‘) exec dbms_java.grant_permission (‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘,‘your user_dump_dest‘, ‘read‘) create a wrapper package for utl_file pk_utl_file.sql As TFMADMIN set up the tables, views and sequence tfmadmin_objects.sql create the controlling package pack_trace_file_manager.sqlJava Layer TraceFileDisplay.java you need to compile this and use loadjava to deploy it into the TFMADMIN account sample compilation & load - see javacomp.txt test the Java layer - RECOMMENDED I have seen occasions where the java security layer behaves unpredictably and this can result in the Trace File Display utility falsely reporting that there are no trace files in the trace directories. consequently it is a sensible idea to verify that your java layer is behaving as expected before you try starting up the utility as TFMADMIN, try this exec pack_trace_file_manager.pc_generate_file_list (‘BACKGROUND‘) if you get a "PL/SQL procedure completed successfully" then everything is OK if you get something like this ... * ERROR at line 1: ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: th (java.io.FilePermission D:OCCdboratraceack read) has not been granted to TFMADMIN. The PL/SQL to dbms_java.grant_permission( ‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘, ‘D:OCCdboratraceack‘, ‘rea ORA-06512: at "TFMADMIN.PACK_TRACE_FILE_DISPLAY", line 45 ORA-06512: at "TFMADMIN.PACK_TRACE_FILE_DISPLAY", line 135 ORA-06512: at line 1 then you will need to sort it out before you go any further. Firstly, check out Note:137280.1 on Metalink. If the error persists beyond the solution suggested here then try; as SYS grant JAVASYSPRIV, JAVAUSERPRIV to tfmadmin; If this does not help then you can always adopt the "Mit Kanonen auf Spatzen schie遝n" approach (Shooting sparrows with canons ...) ; exec dbms_java.grant_permission (‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘,‘<<ALL FILES>>‘, ‘read‘); If that doesn‘t work then raise it with Oracle Support - there may well be a fundamental problem with your java layer.Apahe / PHP layer If you haven‘t already done so, deploy Apache and PHP in a centralised location. see http://otn.oracle.com/tech/opensource/php/apache/inst_php_apache_windows.html for a handy guide to deployment source code ; listTargets.php listFiles.php * retrieveTraceFile.php * tkprofDialog.php deleteFilesConfirmation.php * you may need to either remove or edit the YourDomain tag in here I found the easist way to make the oci connection work from a php source file was to specify the full connection string as it would appear in the tnsnames.ora - In our environment this included a domain name - what you do will depend on your personal environment ... configuration files user.conf - contains the username & password for db connections made to the TFMADMIN account from the php layer - edit as required targets.conf - contains a list of the connection details for the databases where TFMADMIN is deployed - edit as required cascading stylesheet - not supplied

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值