久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='r2COE'><tr id='r2COE'><dt id='r2COE'><q id='r2COE'><span id='r2COE'><b id='r2COE'><form id='r2COE'><ins id='r2COE'></ins><ul id='r2COE'></ul><sub id='r2COE'></sub></form><legend id='r2COE'></legend><bdo id='r2COE'><pre id='r2COE'><center id='r2COE'></center></pre></bdo></b><th id='r2COE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='r2COE'><tfoot id='r2COE'></tfoot><dl id='r2COE'><fieldset id='r2COE'></fieldset></dl></div>
    1. <small id='r2COE'></small><noframes id='r2COE'>

      1. <tfoot id='r2COE'></tfoot>

          <bdo id='r2COE'></bdo><ul id='r2COE'></ul>
        <legend id='r2COE'><style id='r2COE'><dir id='r2COE'><q id='r2COE'></q></dir></style></legend>

        檢查字符串是否代表Java中的整數的最佳方法是什

        What#39;s the best way to check if a String represents an integer in Java?(檢查字符串是否代表Java中的整數的最佳方法是什么?)
        <tfoot id='yyVeu'></tfoot>

            <i id='yyVeu'><tr id='yyVeu'><dt id='yyVeu'><q id='yyVeu'><span id='yyVeu'><b id='yyVeu'><form id='yyVeu'><ins id='yyVeu'></ins><ul id='yyVeu'></ul><sub id='yyVeu'></sub></form><legend id='yyVeu'></legend><bdo id='yyVeu'><pre id='yyVeu'><center id='yyVeu'></center></pre></bdo></b><th id='yyVeu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yyVeu'><tfoot id='yyVeu'></tfoot><dl id='yyVeu'><fieldset id='yyVeu'></fieldset></dl></div>
            <legend id='yyVeu'><style id='yyVeu'><dir id='yyVeu'><q id='yyVeu'></q></dir></style></legend>

                <bdo id='yyVeu'></bdo><ul id='yyVeu'></ul>

              • <small id='yyVeu'></small><noframes id='yyVeu'>

                    <tbody id='yyVeu'></tbody>
                • 本文介紹了檢查字符串是否代表Java中的整數的最佳方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我通常使用以下成語來檢查字符串是否可以轉換為整數.

                  I normally use the following idiom to check if a String can be converted to an integer.

                  public boolean isInteger( String input ) {
                      try {
                          Integer.parseInt( input );
                          return true;
                      }
                      catch( Exception e ) {
                          return false;
                      }
                  }
                  

                  只有我一個人,還是這看起來有點駭人聽聞?有什么更好的方法?

                  Is it just me, or does this seem a bit hackish? What's a better way?

                  查看我的答案(帶有基準,基于 早期答案.com/users/28278/codingwithspike">CodingWithSpike) 了解我為什么改變立場并接受 Jonas Klemming 的回答 這個問題.我認為這個原始代碼會被大多數人使用,因為它實現起來更快,更易于維護,但在提供非整數數據時速度會慢幾個數量級.

                  See my answer (with benchmarks, based on the earlier answer by CodingWithSpike) to see why I've reversed my position and accepted Jonas Klemming's answer to this problem. I think this original code will be used by most people because it's quicker to implement, and more maintainable, but it's orders of magnitude slower when non-integer data is provided.

                  推薦答案

                  如果您不關心潛在的溢出問題,此函數的執行速度將比使用 Integer.parseInt() 快 20-30 倍.

                  If you are not concerned with potential overflow problems this function will perform about 20-30 times faster than using Integer.parseInt().

                  public static boolean isInteger(String str) {
                      if (str == null) {
                          return false;
                      }
                      int length = str.length();
                      if (length == 0) {
                          return false;
                      }
                      int i = 0;
                      if (str.charAt(0) == '-') {
                          if (length == 1) {
                              return false;
                          }
                          i = 1;
                      }
                      for (; i < length; i++) {
                          char c = str.charAt(i);
                          if (c < '0' || c > '9') {
                              return false;
                          }
                      }
                      return true;
                  }
                  

                  這篇關于檢查字符串是否代表Java中的整數的最佳方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                    <bdo id='EWpWL'></bdo><ul id='EWpWL'></ul>

                    • <legend id='EWpWL'><style id='EWpWL'><dir id='EWpWL'><q id='EWpWL'></q></dir></style></legend>
                      • <tfoot id='EWpWL'></tfoot>

                          <small id='EWpWL'></small><noframes id='EWpWL'>

                          1. <i id='EWpWL'><tr id='EWpWL'><dt id='EWpWL'><q id='EWpWL'><span id='EWpWL'><b id='EWpWL'><form id='EWpWL'><ins id='EWpWL'></ins><ul id='EWpWL'></ul><sub id='EWpWL'></sub></form><legend id='EWpWL'></legend><bdo id='EWpWL'><pre id='EWpWL'><center id='EWpWL'></center></pre></bdo></b><th id='EWpWL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EWpWL'><tfoot id='EWpWL'></tfoot><dl id='EWpWL'><fieldset id='EWpWL'></fieldset></dl></div>

                              <tbody id='EWpWL'></tbody>
                            主站蜘蛛池模板: 91伊人网| 欧美亚洲日本 | 欧美日韩理论 | www久久 | 免费观看色 | 国产精品揄拍一区二区 | 欧美精品v | 国产精品无码专区在线观看 | 成人在线观看免费视频 | 91国产在线播放 | 三级黄色片在线 | 亚洲综合视频 | 麻豆av网站 | 欧美日韩综合精品 | 成人免费xxxxx在线视频 | 殴美黄色录像 | 一区二区三区在线观看视频 | 国产激情精品一区二区三区 | 欧美日韩国产三级 | 日韩视频精品 | 九九热久久免费视频 | 中文字幕一区二区三区四区 | 国产精品视屏 | 日本三级做a全过程在线观看 | 中文字幕视频在线 | www久久国产 | 中文字幕欧美一区二区 | 国产一区二区在线免费观看 | 成人免费区一区二区三区 | 日本一区二区电影 | 国产不卡一区在线观看 | 精品一区二区在线看 | 国产在视频一区二区三区吞精 | av天天澡天天爽天天av | 久色视频在线 | 一区精品在线观看 | 亚洲欧美在线观看 | 日韩成人高清 | 国产激情一区二区三区 | 国产成人av免费看 | 久久三级av |