stringbuffer

Java: StringBuffer & Concatenation

Hi guys, I'm using StringBuffer in Java to concat strings together, like so: StringBuffer str = new StringBuffer(); str.append("string value"); I would like to know if there's a method (although I didn't find anything from a quick glance at the documentation) or some other way to add "padding". Let me explain; every time I append s...

Correctly over-loading a stringbuf to replace cout in a MATLAB mex file

MathWorks currently doesn't allow you to use cout from a mex file when the MATLAB desktop is open because they have redirected stdout. Their current workaround is providing a function, mexPrintf, that they request you use instead. After googling around a bit, I think that it's possible to extend the std::stringbuf class to do what I ne...

How is a StringBuffer passing data through voids with no fields in the Class?

Given: Class has no fields, every variable is local. littleString was created by refactoring bigString in Eclipse: public String bigString() { StringBuffer bob = new StringBuffer(); this.littleString(bob); return bob.toString(); } private void littleString(final StringBuffer bob) { bob.append...

What's the equivalent C# method to this basic Java method?

Hi folks, really simple question here (more to confirm my thoughts, than anything)... Java method : [StringBuffer.Delete]1; [1]: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html#delete(int, int) Java Code: sb.delete(sb.length()-2, sb.length()); C# (not sure if this is right): StringBuilder sb = new StringBuild...

How to get adress of a Java Object?

Is there a way to get address of a Java object? Where the question comes from?: At First, I read properties file and all the data from file was placed into table. Properties file can update. So, I want to listen that file. I listen an object using PropertyChangeSupport and PropertyChangeListener. updatedStatus = new basit.data.MyStri...

Strings are immutable - that means I should never use += and only StringBuffer?

Strings are immutable, meaning, once they have been created they cannot be changed. So, does this mean that it would take more memory if you append things with += than if you created a StringBuffer and appended text to that? If you use +=, you would create a new 'object' each time that has to be saved in the memory, wouldn't you? ...

New Object Creation in recursive Java program

Hi there, Java newbie here looking for some help. Here is the code in question: public void generateCodeTable(Node tree, StringBuffer buf) { if (tree != null) { StringBuffer newSB = new StringBuffer(); newSB.append(buf); if (tree.key != '$') { System.out.print(tree.key + "(" + ...

Does the StringBuffer equals method compare content?

Possible Duplicate: Comparing StringBuffer content with equals StringBuffer s1= new StringBuffer("Test"); StringBuffer s2 = new StringBuffer("Test"); if(s1.equals(s2)) { System.out.println("True"); } else { System.out.println("False"); } Why does that code print "False"? ...

J2ME/Java: Referencing StringBuffer through Threads

This question might be long, but I want to provide much information. Overview: I'm creating a Stock Quotes Ticker app for Blackberry. But I'm having problems with my StringBuffer that contains an individual Stock information. Process: My app connects to our server via SocketConnection. The server sends out a formatted set of strings th...

Adding an Object to Vector loses Reference using Java?

I have a Vector that holds a number of objects. My code uses a loop to add objects to the Vector depending on certain conditions. My question is, when I add the object to the Vector, is the original object reference added to the vector or does the Vector make a new instance of the object and adds that? For example, in the following code...

What's a good way of building up a String given specific start and end locations?

(java 1.5) I have a need to build up a String, in pieces. I'm given a set of (sub)strings, each with a start and end point of where they belong in the final string. Was wondering if there were some canonical way of doing this. This isn't homework, and I can use any licensable OSS, such as jakarta commons-lang StringUtils etc. My com...

remove certain lines from a StringBuffer

A legacy app program has a huge String Buffer (size sometimes upto an Mb) and it is processed sequentially for modifying the contents. I have to implement a change wherein I need to update the string buffer to remove some lines starting with certain specific words. What are the possible ways to implement this ? Ex: ABC:djfk kdjf kdsjfk...

Java regex replaceAll does not replace string

I want the text "REPLACEME" to be replaced with my StringBuffer symbols. When I print symbols, it is a valid string. When I print my query, it still has the text REPLACEME instead of symbols. Why? private String buildQuery(){ String query = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%...

Java StringBuffer questions

class MyStringBuffer { //TODO explain: why you would need these data members. private char[] chars; //character storage. private int length; //number of characters used public String toString(){ //TODO //Hint: just construct a new String from the ‘chars’ data member //and return this new String...

Java StringBuffer questions: How do I append something in this situation?

package homework5; import java.io.*; import java.util.Arrays; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { MyStringBuffer strTest = new MyStringBuffer(); // FIX ME if you see the following string is not on the same line System.out.println...

Java StringBuffer append allocation.

When using StringBuffer in java, I'm wondering how the append function is implemented when it needs to reallocate space. For example, if I append a string longer than the currently allocated space, how does it manage this in the details of the method? ...

Add character a place in String

Hi I'm trying to make a method that shall help me to spell world right. After addChar have return its work based on the input "famili", I want the result array to contain the word "familiy". Now the method removes a character from the string and replace it with the current char in alpha[], can someone please give me some help to make th...

Java : Clearing StringBuffer contents

All, I was wondering if clearing a StringBuffer contents using the setLength(0) would make sense. i.e. Is it better to do : while (<some condition>) { stringBufferVariable = new StringBuffer(128); stringBufferVariable.append(<something>) .append(<more>) ... ; Append stringBuff...