How can I create a string

Hello guys

why doesn't the line

[code:]

string msg = ("my msg");

[/code]

works? do I need to import something at the begining of my application?

another question: how to add text to a container? If string msg would work, then

container.add(msg);

might work, right?

[323 byte] By [tleis] at [2007-9-30 20:25:28]
# 1

Your code should be:

String msg = "my msg";

Note that String starts with a capital "S" - Java is case sensitive. Also note that you don't need the round brackets around your string the way you have it - this isn't an error, just a matter of code style.

You don't need to import anything to use the String class since it is in the java.lang package which is imported automatically.

For your second question, the answer depends on what you mean by "container". If you're referring to the collections API, like Vector, ArrayList, or some such, then yes, you can just add a String to it the same way you'd add any other object. However, if you mean container as in java.awt.Container, then no, you can't add a String that way. You have to put the String into a component like a java.awt.Label or a javax.swing.JLabel before you can add it to your java.awt.Container.

scorbett at 2007-7-7 1:10:02 > top of Java-index,Administration Tools,Sun Connection...
# 2
You also can use the sintaxString msg = new String ("my msg");with this line it all creates a new position in the memory with the object....Positive VibrationsLucas Ferst
lgferst at 2007-7-7 1:10:02 > top of Java-index,Administration Tools,Sun Connection...