Raymond Tong wrote:You should iterate your List and print its item.
By the way, your printObj method not actually print object, it returns a string which should be renamed.
About iterating :
I used this method to my class
But when i call this method from main it throws this exception
Exception in thread "main" java.util.ConcurrentModificationException
Java Result: 1
I also changed the code above adding Iterating
It works ,it prints 0 as it should have done.Now i ll try to pass this idea to a bigger application i hope i wont find any problems there yet i would like you to explain me if you dont mind what's going on with the part :
Raymond Tong wrote:
MyClass clazz = (MyClass) myList.get(i);
this is what i dont get how its working...
So, before that, List does not specific Type it can hold.
You can add almost anything inside.
So when you try to get its content by get(n), it would return Object. (any class is implicitly extends Object)
Because you want to work on MyClass, you do type casting by.
If you want to get rid of type casting, you should use Generics, like
Now, because if has specified to save MyClass, when you get its content, it would return MyClass.
I would suggest you to read some tutorial to understand more on fundamental concept of Java
Or get a book about Java (e.g. Head First Java)
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
The WEB SERVICES and JAX-RS Coursehttps://coderanch.com/t/690789/WEB-SERVICES-JAX-RS