《算法第四版》官方jar包中In的readStrings()方法不建议使用的解决办法

起因:在学习《算法第四版》过程中总是遇到一些算法之外的小问题,比如本书中所需要下载的库。今天在学习排序那一节时,发现排序框架main()方法中的In的readStrings()方法不能使用,google了半天也没有找出解决方案,遂自己到algs4这个包里面查看此方法的源码(具体位置为edu.princeton.cs.algs4.In),代码如下:

   /**
     * Reads all strings from a file and returns them as
     * an array of strings.
     *
     * @param      filename the name of the file
     * @return     the strings in the file
     * @deprecated Replaced by {@code new In(filename)}.{@link #readAllStrings()}.
     */
    @Deprecated
    public static String[] readStrings(String filename) {
        return new In(filename).readAllStrings();
    }

由注释@deprecated Replaced by {@code new In(filename)}.{@link #readAllStrings()}.可以看到,这个方法已经被弃用了,因此只要将main()中读取字符串的代码改为String[] a = new In("tiny.txt").readAllStrings(); 此时程序就可以正常运行了

完整main()方法如下:

    public static void main(String[] args) {
        String[] a = new In("tiny.txt").readAllStrings();
        System.out.println(a);
        sort(a);
        assert isSorted(a);
        show(a);
    }
  • 8
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值