Some Useful JAVA String technique

1. When Concatenating String…

  • Do use Character array or String Builder
  • Do not use str +=str, The time complexity for this method is O(n^2) !
  1. Character array : O(n)

    String a ="BoilingPoint";
    char[] chars = a.toCharArray();
    
  2. StringBuilder : O(n)

    StringBuilder str = new StringBuilder();
    for(int i=0;i<n;i++){
        str.append("hello");
    }
    String s = str.toString();
    

2. When Storing Substring of s that contains characters…


© 2018. All rights reserved.

Powered by Hydejack v8.5.2