Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  yet another simple q, about String  (Read 1183 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Posted 2005-02-22 17:41:31 »

hey what is the max size that a Java string can be? is there a way to find out?

Kommi
Offline javatypo

Junior Member





« Reply #1 - Posted 2005-02-22 19:12:06 »

i dont think there is really a set one, but i think its either 256 bytes, or just the size of your ram. but i think you'll find in alot of programming, you'll never really need to have a string be some crazy large amount of memory. if you are working with that much memory, it would likely be easier to work with it in chunks, and just take chucks at a time out of a file or where ever it is that u are getting the string.

of course, u always have the question of how do word processors store all that data, but we havent really got that far in computer science lol.. apparently it was a really neat idea or something, and almost an accident to how they did that.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2005-02-22 19:27:07 »

Quote
i dont think there is really a set one, but i think its either 256 bytes, or just the size of your ram.


Ahem. I was using String's back in java 1.2 that were so long I was one of those who found the bug in Swing where JTextArea only returned a max of 32kb of data from its getText() method Grin.

I've certainly had String's well over 100Kb, and IIRC over a meg; I think I once loaded a massive logfile (many meg) as a single string (experimenting with different ways to load and manipulate logfiles in efficiently large chunks in the days before NIO).

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2005-02-22 19:31:38 »

Quote

of course, u always have the question of how do word processors store all that data


I think I know what you're referring to (some trick with dealing with storing it in one long byte string), but these days if you're writing a new one you'd probably just go the easy route and use parse-trees.

Look at XML's DOM for the general idea (use a separate object for each chunk of text that has an attribute; if you select some text in a chunk and change the formatting of half of it, it splits the chunk into two chunks, and adds extra info onto the piece that you changed).

This is, literally, the easiest way for a computer to deal with the info; programmatically accessing and altering it, AND converting to any other form is easiest if it starts in this form.

Of course, this is precisely why DOM was adopted for manipulating XML docs: because it's the most convenient arrangement for humans to write code to access / change / interpret.

malloc will be first against the wall when the revolution comes...
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2005-02-22 19:59:31 »

So far I only used Strings, which were up to 500kb.

Well, it's basically only limited by the heapsize... and heh... length() returns an int... so 2^32... and it's signed... so the half of it, which means 2,147,483,647 chars is the maximum.

弾幕 ☆ @mahonnaiseblog
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #5 - Posted 2005-02-23 20:38:10 »

second question: what is the max size of a StringBuffer? and where can I find the info myself so I dont keep flooding the forums with stupid questions?

Kommi
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #6 - Posted 2005-02-23 20:55:23 »

You're actually asking questions either about the java-language (in which case there is only ONE place: the Java Language Specification, available both as a book AND always in it's latest version as a massive document on java.sun.com) or about specific implementations (in which case you just have to hope the vendor publishes detailed information on which parts of the JLS they implement to what level of certainty/quality. They should implement the whole thing perfectly, but bug parade proves that's not the case Wink).

Since Sun isn't great at publishing impl information (I've never heard them openly and obviously admit to any of the major fundamental mistakes they made, only ever seen 3rd parties collate lists, evidence, etc OR seen them on bug reports) you are pretty much stuck with:
- read the JLS to see if it states what the JVM must do in your given question
- ...ask around to see if there's any common knowledge about whether JVM X actually does as it is required to. Although the answer to this is very nearly always "yes" there are occasions when it's "no". So usually you don't bother asking unless EITHER the JLS doesn't actually specify (rare) or you can't seem to find the right part of the JLS that answers your Q (common Wink), or you have some reason to be suspicious (e.g. the JVM crashes every time you try to make a string of a certain huge length).

malloc will be first against the wall when the revolution comes...
Offline tom
« Reply #7 - Posted 2005-02-23 21:22:27 »

Just look at the source. It can be downloaded with the jdk. It looks like the maximum is Integer.MAX_VALUE.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (17 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (38 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!