Moraki
Moraki

Reputation: 243

Excluding max length, what limitations does a string in java have?

Excluding max length, what limitations does a string in java have?

Are there things I cant put in one? Characters they wont accept?

Any would be a great help :)

Upvotes: 2

Views: 245

Answers (3)

Gandalf
Gandalf

Reputation: 2348

Depending on your usage scenario: Java uses UTF-16 for String representation meaning that Strings in Java might use more Memory than UTF-8/ASCII/ISO-XXXXX.

Upvotes: 2

user980505
user980505

Reputation:

I'm not sure, but maybe there is a limit on the length of the string Integer.MAX_VALUE

public final class String
  111     implements java.io.Serializable, Comparable<String>, CharSequence
  112 {
  113     /** The value is used for character storage. */
  114     private final char value[];

String.java

Upvotes: -2

Polynomial
Polynomial

Reputation: 28316

Java strings can contain any data you like, they're binary strings. However, certain functions may not work with malformed strings (e.g. containing \x00), depending on your specified character encoding. You can (probably) rely on the standard methods to work, but keep in mind that by inserting "bad" characters you're abusing the type, and you may break other people's code.

Upvotes: 3

Related Questions