Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 31503

A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.

36 votes
Accepted

Reverse a String in Java

Strings are immutable, cannot be changed. Java is relatively slow at allocating/cleaning memory, try to avoid it. Java can 'inline' method calls and make methods really fast. …
rolfl's user avatar
  • 97.5k
31 votes

Custom indexOf() without String methods

Complexity Pedantically, the time-complexity is \$ O( m \times n ) \$, where m is str.length and n is substr.length. This matters when \$ \left| m-n \right| \$ is large. The Space complexity is \$ O …
rolfl's user avatar
  • 97.5k
25 votes
Accepted

Capitalize the first character of all words (even when following a '-')

Your problem is an interesting one,but your solution is not a great use of regular expressions, since there's the better option of using the 'word boundary' anchor \b. The boundary anchor matches a t …
rolfl's user avatar
  • 97.5k
23 votes
Accepted

Integer seconds to formated string mm:ss

Your code looks functional, and, if this was for early versions of Java, it would be quite typical and standard. The String.format process can do so much more than what you are using it for, though. …
rolfl's user avatar
  • 97.5k
22 votes

Fast way of searching for a string in a text file

Fast comes at a price.... code complexity and perhaps readability. Assuming that your code produces the right results now.... and it is a big assumption because: it expects the word to be at the be …
rolfl's user avatar
  • 97.5k
17 votes
Accepted

Finding anagrams - Empires strike back

For an interview, I really would not hold your answer against you, but, for your interest, if you sort the letters in the term, and then sort the letters in the same-length words, if the resulting strings
rolfl's user avatar
  • 97.5k
17 votes

Reversing a String using Stack

This question provides a really good example of how learning 'tools' is important, but understanding efficiency is better. The purpose of the task was probably to teach you to use a stack, but there …
rolfl's user avatar
  • 97.5k
16 votes
Accepted

Reversing the digits of an integer

In Java, and in Code Review, the preference is for creating both highly readable, and highly efficient code. It is an almost bizarre fact, that one leads to the other. your code has one efficiency, …
rolfl's user avatar
  • 97.5k
15 votes
Accepted

Split string in half and change case accordingly

Midpoint math is often a pain in the whatnot, but a real trick is to add 1 to the length before halving it. Additionally, instead of repeating the math multiple times, you can do it just once. def si …
rolfl's user avatar
  • 97.5k
15 votes
Accepted

Count frequency of words in a given file

There are a number of things in here you have done well, and your algorithm is good. I like that you have created an object to contain the frequency. Using the HashMap is the right solution too. Over …
rolfl's user avatar
  • 97.5k
14 votes

Finding words of different lengths given six letters

This problem begs for recursion.... private static final void checkWord(char[] chars, char[]current, int len, List<String> results) { if (len == chars.length) { final String result = new …
rolfl's user avatar
  • 97.5k
12 votes
Accepted

Code Hunter 2.06: Count occurrences of 'a' in a string

This is a nice short piece of code, though it has a number of 'features' which can be improved. Code Style Java code style recommends a lower-case letter to start method names.... Puzzle should be p …
rolfl's user avatar
  • 97.5k
12 votes
Accepted

Text centering function in bash

Since you are using printf to output the spaces, you may as well use a specific printf format for the output. Here's a replacement function: centerQ(){ textsize=${#1} width=$(tput cols) span=$ …
rolfl's user avatar
  • 97.5k
12 votes
Accepted

Arranging words in sentences alphabetically

Your code here is far more complicated than it needs to be. The trick you need to follow is four-fold: Use your library functionality Use Regular Expressions Use buffered input/output for performanc …
rolfl's user avatar
  • 97.5k
11 votes
Accepted

Simple dice roll using std::string as dice notation

Bug Your code has an integer-division/multiplication problem/bug. Consider the dice-roll specification 10d10+0. Your code will parse this down to: string dicePart1 = "10"; string dicePart2 = "10"; …
rolfl's user avatar
  • 97.5k

1
2 3 4 5
8
15 30 50 per page