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?

14th Nov 2016, 7:16 PM
Vishnu Vijay P
Vishnu Vijay P - avatar
5 Respostas
+ 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 :)
14th Nov 2016, 7:23 PM
Burey
Burey - avatar
+ 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.
14th Nov 2016, 10:19 PM
Alex Ruiz
Alex Ruiz - avatar
+ 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);
15th Nov 2016, 9:52 PM
Maksym Zieliński
Maksym Zieliński - avatar
+ 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
14th Nov 2016, 7:20 PM
P Sandesh Baliga
P Sandesh Baliga - avatar
0
so if I give integer instead of string, that will be an error right?
14th Nov 2016, 7:22 PM
Vishnu Vijay P
Vishnu Vijay P - avatar