the (0) element to something and print it out. Why do i get an error?
Vector<String> string = new Vector<>();
string.get(0) = "some string";
System.out.println(string.get(0));
The error: Variable expected
I also tried using the set() method: Vector<String> string = new Vector<>(); string.set(0, "sss"); I get Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
asking this, it's kind of "WTF" ... It seems you missed out java basic knowledge.
Yes, I'm new to java. and I need to use vectors. Since it's such a basic question, just give me a simple answer, I don't think it would take more than a couple minutes of your time.
Why Vector why not ArrayList?
I have time, but I won't give you any tip about the error since the error is so easy to fix, I let you find it by your own. 🤷♂
Because you can't change the size in arrays
Well, you could've just answered the question instead of wasting your precious time on arguing about it tnx anyway
I looked up ArrayList, I'll use it, tnx
First of all, read what vector, array and arraylist is in java. But to answer the question. Your array contains no elements. Im assuming you come from a language where initialization happens at variable creation time... welcome to java, where almost everything is a pointer
Обсуждают сегодня