Search code examples
javaimportstringbuffer

How can I see if a Class is built into Java?


I'm doing a Java project at the moment and feel that StringBuffer would help a lot in performing this particular task, where I am 'building' a string representation of a Matrix:

/**
 * Returns a String representation of the Matrix using the getIJ getter
 * function. You should use MaF.dF to format the double numbers to a
 * sensible number of decimal places and place the numbers in columns.
 * 
 * @return A String representation of the Matrix
 */
public String toString() {
    //String stringBuilder = new String
    StringBuffer beep = new StringBuffer;
    for(i=0; i<m-1; i++){
        for(j=0; j<n-1; j++){

        }
    // You need to fill in this method
}

I've tried it in a Java program by itself and it seemed okay, but then I tried some sample Java program from online and it didn't compile. Is StringBuffer built into Java, or would it require importing a package? I am not allowed to import any packages for this project.

Also, if anyone could tell me what exactly MaF.dF is? How it is used? I think it's part of MaInput which I cannot find anything on online.


Solution

  • StringBuffer is built into Java and you do not need to import any package. (Its package is java.lang which is "automatically" imported.)

    See: http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html

    Check the code below. It runs without any import.

    public class StringBufferUse {
        public static void main(String[] args) {
            StringBuffer sb = new StringBuffer();
            sb.append("a");
            sb.append("b");
            sb.append(123);
            System.out.println(sb.toString()); /* prints "ab123" */
        }
    }