Scanner vs. StringTokenizer vs. String.Split

前端 未结 10 1318
太阳男子
太阳男子 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:48

    StringTokenizer was always there. It is the fastest of all, but the enumeration-like idiom might not look as elegant as the others.

    split came to existence on JDK 1.4. Slower than tokenizer but easier to use, since it is callable from the String class.

    Scanner came to be on JDK 1.5. It is the most flexible and fills a long standing gap on the Java API to support an equivalent of the famous Cs scanf function family.

提交回复
热议问题