1
vote
4answers
500 views

Regex to String generation

Let's say that we have a regex and an index i. If we suppose that the set of strings that match our regex are sorted in a lexicographical order, how could we get the i element of this list? Edit : I ...
1
vote
2answers
169 views

What's the difference of an object being final and an object being immutable in java?

final String str = "do not change me"; str = "why not?"; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed ...
1
vote
4answers
207 views

How can I take a list of tokens (of variable number) and know what each token means?

I have to read a text document with data formatted as follows: (a couple of examples) 07 M W F 1400 1450 C 2004 M W F 0900 1030 EN 2036 06 M T R 1300 1350 EN 1003 17 T R 0900 1015 EN 1052 The ...
11
votes
3answers
1k views

How many strings are created in memory when concatenating strings in Java?

I was asked about immutable strings in Java. I was tasked with writing a function that concatenated a number of "a"s to a string. What I wrote: public String foo(int n) { String s = ""; for ...
17
votes
2answers
4k views

Why does Java use UTF-16 for internal string representation?

I would imagine the reason was fast, array like access to the character at index, but some characters won't fit into 16 bits, so it wouldn't work... So if you have to handle special cases anyways, ...
7
votes
2answers
9k views

When should I use StringBuilder or StringBuffer?

In a production web application, my fellow programmers used StringBuffer everywhere. Now I am taking care of application development and corrections. After reading StringBuilder and StringBuffer I ...
14
votes
5answers
5k views

Should a string constant be defined if it's only going to be used once?

We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application. This is done by implementing classes which map strings ...
0
votes
2answers
7k views

Best practice Java - String array constant and indexing it

For string constants its usual to use a class with final String values. But whats the best practice for storing string array. I want to store different categories in a constant array and everytime a ...
10
votes
6answers
865 views

What are the pros and cons of having a CaseInsensitiveString type in Java?

I'm tempted to create a final class CaseInsensitiveString implements CharSequence. This would allow us to define variables and fields of this type, instead of using a regular String. We can also have ...
2
votes
3answers
4k views

Why does Java's String class not implement a more efficient indexOf()?

Following the below question on Stack Overflow http://stackoverflow.com/questions/5564610/fast-alernative-for-stringindexofstring-str I got to wondering why it is that java (6 at least) not use a ...