memory « string « Java Data Type Q&A

1. Fastest way to find duplicates in a string without using any additional memory in java?

What is the fastest way to remove duplicate character in a string without using an extra memory in Java?

2. How to deal with big strings and limited memory

I have a file from which I read data. All the text from this file is stored in a String variable (a very big variable). Then in another part of my app I ...

3. What is the difference Between Assignment and Creating Instance of String?

In an interview question, Interviewer asked me What is the common and difference between the following statements:

String s = "Test";

String s = new String("Test");
Is there any difference in memory allocation?

4. What is String Local Memory in Java?

In a JVM the memory is split into Method Area ,Stack ,Heap , Temp and Registry . what is String Local Memory ? Does this exists ? If so when ...

5. string memory allocation

which one is better

System.out.println("hello world");
String s="hello world";

6. string memory allocation

Possible Duplicate:
string memory allocation
What is the difference between
System.out.println("hello world");
System.out.println("hello world");
String s="hello world";
and which one is better?

7. String class in specific languages

I'm becoming more interested in API's and was about starting to write my own, but then I was thinking a bit about the standard library of Java. The standard library of Java ...

8. String memory allocation in java

In an Servlet class, I am having the checks if("Mail".equals( request.getParameter(mode)) || "Chat".equals( request.getParameter(mode))) {} My question is about the memory allocated for the strings "Mail" and "Chat". Will it create new string objects ...

9. Memory conscious string filtering

Lets say I have 500 words:

... + 494 more words
I have following text that is about 85KB in total:
Marting went and got him self stuff from Hopa store ...

10. Memory allocation in Java Strings


String x = "abc";
 String y = "abc";
What is the memory allocation for x and y ?

11. Question about parsing text manipulation approach

I need to parse a long file in Java and output the results to another file. Since I need to average across several items, and I need to parse the file to ...

12. Java String Memory Leak

I am not java expert. My code is reading a file into a String. This code gets executed every 5 minutes. The size of file varies. Sometimes it is 100 sometimes it ...

13. Java String Memory Leak II

I have ask similar question before : Java String Memory Leak. But I was not sure what to ask: Here is another piece of code I wrote:


public class ...

14. String and memory

class A {

  public void someMethod() {
         String var = "Abhi";
         var = "Abhishek";

15. Strings memory model

What I read about strings is when a string object is created in Java it is immutable. For example:

String s=new String();
Does the String s no longer point to "abc"? And another ...

16. strings and memory allocation in java?

one thing that i always wondered, if i have a method like this:

String replaceStuff (String plainText) {
        return plainText.replaceAll("&", "&");
will it create new String ...

17. freeing up of memory used by strings

18. String Memory Question

Hello, can any body explain me why the output of this coming out only "same values"... because what i read is that JVM creats a pool memory for x1 ,x2 and for "c"... After concatenation the resulting value of x2 is same as that of reference x1 i.e "abc" so why the comparision is giving false result.... public class Simple { ...

19. String Memory Allocation....

A Java String is an object, just like any other Java class. You can see the complete source code for it -- it comes with the JDK download, along with the Java source to the entire API. A String has a char[] as a member, along with a couple of ints for holding the offset and length of the characted in ...

20. String -memory address

21. Memory Allocation for Strings

Hi All, I have a doubt on the allocation of memory for String Literals, I have a big application where we log(using Log4j) lot of information as below, the implementation of info method is done by us to write the data to a file."Data To Be Logged"); My Doubt is will the above String "Data To Be Logged" be stored ...

22. String literals and memory.

Once a String literal gets referenced by the constant pool, does it ever get taken out of memory? Possibly such as the class it was coded in gets GC'ed and the class which created the String literal is no longer in the heap? Or is it that once the String literal reference is in the constant pool, there is always a ...

23. Load 20000 String Objects into Memory

Hi All, How to load 20,000 String Objects into a HashSet and keep it those Keep that into memory so any class can find information from memory. Those string objects will be like real long Strings. ABCCORPORATIONABC MYNAMEISEARLHIKKI MYNAMEISABCDABCD There are 20,000 strings like this always loaded into memory and i want to do a patter matching on them, for example ...

24. Why only Strings are handled in a different kind of memory pool?

Hi all, I have this question, may be this was answered so many times by you guys. but I hope to get a satisfactory answer again. (1) Why only Strings are handled in a different kind of memory pool? (2) why they are made immutable, and How Java has implemented immutability in Strings? (3) How can we make an object immutable? ...

25. memory wasted in string pool...

26. Pool of Interns Memory(String literals)

27. Simple question about Strings in memory

28. how memory is managed for string[]

29. Printing memory address instead of string value.

Ok, so I have a project i'm working on for school and i'm stumped at a particular point in this project. I think it may have to do with my parent class called "Student" and it being an abstract class, however i'm not sure. What is happening, is my program is displaying the following output; which appears to be the memory ...

30. Total memory won't reduce after freeing memory allocated for String?

Hi, I'm confused about this: I load a string from a big text file. After using it, I set the variable to null, then call System.gc(). The used memory reduces, but why not with Runtime.totalMemory()? For example: # java -jar dist/string.jar max: 592.00 MB total: 30.13 MB free: 29.65 MB used: 487.95 KB after loading big file... (text = [...]) max: ...

31. String pool and heap memory

Hi everyone, here i have a confusion about String instantiation . Let suppose I have a code fragment like bellow String str="abc"; String str1="abc"; String st=new String("abc"); when I use a == operator for str and str1(str==str1) String object I will get true. Which means both the reference pointing to a same String object. But when I use a == operator ...

32. String memory Calaution

33. About Strings and Memory

You know, Java was designed over 15 years ago. And the designers are not hanging around these forums just in case somebody wants to ask them why they did something back in the last century. What we do have is the API documentation written by them. Have you read it? Do you have a question about it? Or did you really ...

34. How many bytee in memory string occupies?

Don't try to get fancy, and don't try to be smarter than the JVM or the creators of Java. If you need a String, use a String. Those microoptimizations will just make your code unreadable and unmaintainable, not to mention prevent it from working with standard libraries, and as often as not they'll make performance and memory usage worse, or at ...

35. Strings and Memory management

36. Question regarding String objects and memory

I think there are two objects created by first line, one in string constant pool and one on the heap that is pointed by str1. NOw when the second line is executed, str2 (since its a literal) , will check if there is any object (i.e. with the value "java") in the string constant pool and since it finds one (that ...

37. Question about Strings and memory

Ok, I know that Strings are immutable and everytime you do something like: String test = "abc"; test = test+"def"; there will be 3 string objects made - abc,def and abcdef. Now if I make String test2 = "abc", does that "abc" come from the memory taken by the first "abc" i created or it is a brand new one? Do ...

38. where is String object in memory? and why?

39. Memory usage for String as formal argument

}//End Of }//End Of Class **********************************************************End Of example code********************************************************** Query 1. In the above example decalring a final constant for String lsName will help in utilization of memory Or Not? This constant is then passed to different method call. All the formal String argument will refer to one String Object. The reason to ask this question is because as per my ...

40. String memory allocation

there will be 2 string objects created (assuming those strings have not already been interned). one will be the size of a string object, and the other will be the size of a string object plus 4 characters why are you so interested in memory allocation and strings? what's your underlying concern?

41. Did the Java Writers Get a Little Happy with Memory Use in String class?

The wrapper classes use it for parsing. File uses it for getName and getParent. String uses it for trim. Class uses it for resolving names. Regex uses it. etc. ... Now, I don't know what percentage of usage all that amounts to, but it IS heavily used. So your desire to gain the 2 bytes back would cost enough byte every ...