0
What is <> statement in java?ex: <String>
I just see that in android. ArrayAdapter<String> x=new ArrayAdapter<String>(); like that basically what is this?
5 Answers
+ 5
the ArrayAdapter an an array list of objects into View item which can be displayed by the android application
in your case, an array list of strings
but it can be also a custom adapter for objects of class which you created
read further at:
https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView
example for custom adapter: (starts at section 2, but recommended to go through it all)
https://www.mkyong.com/android/android-listview-example/
also:
https://www.sitepoint.com/custom-data-layouts-with-your-own-android-arrayadapter/
goodluck :)
+ 3
It's a generic type. You can declare classes names like MyClass<T>, for example, and on some methods return type T. When that happens, you will need to instance the class like:
MyClass<String> = new MyClass<>;
Then, if you call those methods, they will return String, instead of the fake type "T" you used in the code of the class.
Those are the generic type, I recommend reading about them. It's useful when using it for things like lists or other stuff that can be generalized, like serialization and deserialization.
+ 2
If you will put an integer to a String type, then yes. Error ahead. But if you will
treat a number as String, then its ok.
Like:
String number = "150";
x.add(number);
+ 1
it is the set which is to be contained in that variable. for example ArrayAdapter<string> means what type of set should the ArrayAdapter contain. it could be any valid datatypes(fundamental or user defined)
hope im clear to you
0
so if I give integer instead of string, that will be an error right?