tags:

views:

106

answers:

6

I created a class in NetBeans that will be used for string manipulation only. What imports should I use.

I can't even declare a string variable because it didn't autogenerate imports for me. :P Since I'm new, I have no clue what is the bare necesities in the Java world.

This isn't working:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloworld;

import java.text;

/**
 *
 * @author Sergio
 */
public class WordManipulations 
{
    public string[] ReturnAllVowels()
    {
        return string[] x;


}
}

It says that string ;Cannot find symbol;

+5  A: 

Java identifiers are case sensitive; you want String. Also, no imports are required; java.lang is implicitly imported by the compiler.

Ignacio Vazquez-Abrams
and the String class is part of lang package, so nothing else is needed for string manipulation
Jason
If you need more look at the Apache commons libraries. http://commons.apache.org/lang/userguide.html#lang.
Chris Nava
+3  A: 

Capitalize every occurrence of "string".

The import of java.text is unnecessary.

Paul Brinkley
+10  A: 

In Java, its capitalized, so String.

The String class is in the java.lang package. This package is automatically imported into every program.

cletus
Not actually imported... just specially available. If it were imported you would have errors if you made your own class name the same as something in java.lang (which you probably should not do anyways... but not an error).
TofuBeer
@TofuBeer - The JLS (7.5.5) says this: "Each compilation unit automatically imports all of the public type names declared in the predefined package java.lang ... " If the JLS says they are imported, THEY ARE IMPORTED.
Stephen C
@TofuBeer: no, this compiles just fine: `import java.util.*; public class List { /* ... */ }`
Bart Kiers
I said lang not util. I also never said import .*. Try the following code:package stackoverflowtesting;import java.lang.String;public class String { }error message: stackoverflowtesting.String is already defined in this compilation unit
TofuBeer
A: 

As others have said String not string.

Here is a link to the naming conventions used for Java (by Sun). And a tool (checkstyle) that, among other things, can enforce naming conventions - it gives some more examples/detail on naming.

TofuBeer
A: 
Martijn Courteaux
A: 

These sorts of problems simply go away if you are using an IDE. You may find it usful to use one of the following.

mR_fr0g