Scanner vs. StringTokenizer vs. String.Split

前端 未结 10 1317
太阳男子
太阳男子 2020-11-22 10:56

I just learned about Java\'s Scanner class and now I\'m wondering how it compares/competes with the StringTokenizer and String.Split. I know that the StringTokenizer and Str

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 11:49

    Split is slow, but not as slow as Scanner. StringTokenizer is faster than split. However, I found that I could obtain double the speed, by trading some flexibility, to get a speed-boost, which I did at JFastParser https://github.com/hughperkins/jfastparser

    Testing on a string containing one million doubles:

    Scanner: 10642 ms
    Split: 715 ms
    StringTokenizer: 544ms
    JFastParser: 290ms
    

提交回复
热议问题