We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Strings
- Java Substring Comparisons
- Discussions
Java Substring Comparisons
Java Substring Comparisons
Sort by
recency
|
1755 Discussions
|
Please Login in order to post a comment
String smallest = "";
String largest = "";
for(int i = 0; ( i + k )<= s.length(); i++){
Code
public static String getSmallestAndLargest(String s, int k) { String smallest = ""; String largest = "";
this took too long
Substring comparisons in Java are powerful but must be used carefully to avoid common pitfalls like index errors and unnecessary memory usage (in older versions). For readability and safety, prefer utility methods like startsWith(), endsWith(), or regionMatches() when appropriate. Betguru ID