Okay the thing i want to do is make a variable like Line = "hey","you",Mom".
Then later I want to be able to call Line 0 and get the string "hey".
I have something like this:
String[] history = new String "hey","you","Mom";
public String getLine(int index)
{
if (index < 0 || index >= this.history.length)
return null;
}
But this is not working..
How do i make this list? I'm new with the syntax in java.
It's
String[] history = new String[] { "hey", "you", "Mom" };
String[] history = new String[] {"hey","you","Mom"};
String hey = history[0];
This creates a String array with size 3 initialized with the strings hey, you and Mom.
Another option is to use a List:
List<String> history = Arrays.asList("hey","you","Mom");
String hey = history.get(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With