Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: .  (Read 7047 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 15
    • View Profile
« on: March 22, 2014, 09:58:17 pm »

« Last Edit: May 03, 2018, 05:18:37 am by Helios101 »


  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Java equivalent of the following
« Reply #1 on: March 25, 2014, 09:34:39 am »
Am I right when I assume that you are having a problem with Java, not directly JSFML? I am asking because I am a little confused over what the problem is. I believe you are struggling about which Java collection class to use. There are plenty of them, each is optimized for certain use cases. I suggest reading Oracle's documentations or some tutorial on Java collections.

In your case, if you need a dynamic array and you want to access elements by their indices, use the ArrayList. It uses an array internally and is therefore optimized for direct index access. The Vector class does practically the same, but it's a thread-safe version. Unless you need thread-safety, there's no need for you to use the Vector class.

Concerning the decision between ArrayList and Vector, here's a nice little face-off:
« Last Edit: March 25, 2014, 09:40:23 am by pdinklag »
JSFML - The Java binding to SFML.


  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Java equivalent of the following
« Reply #2 on: March 25, 2014, 09:41:11 pm »
My problem is I don't know how to access the abstract run method from the ArrayList object, similar to the way I would go about accessing a virtual function from a vector object in C++
That description is misleading: neither in C++ nor Java, the run method is a part of the container. In fact, containers and collections have absolutely nothing to do with the way you call a method on an object.

I have tried doing the same technique in Java, but I've had no luck.
Java methods are always called with the . operator, there is no explicit dereferencing.

Instead of trying C++ things blindly in Java, you should learn the language properly. There are quite good tutorials on Oracle's homepage, but you could also read a book. To learn how to use ArrayList, have a look at the official Java documentation.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: