I have a recyclerView with a bunch of elements, each element should format and display a Date , the pattern for everyone is the same.

there is

 java.text.SimpleDateFormat android.text.DateFormat 

DateFormat convenient that everything is done in one line, but as I suppose SimpleDateFormat works faster, because it knows the pattern, and DateFormat will DateFormat every call to this pattern, is it correct? On the other hand, DateFormat allows you to not create an object, what is better in this situation? Or maybe one of them is even better in all situations?

Which one is better to use?

    1 answer 1

    If your pattern is always the same, then you need to create a static SimpleDateFormat

     static SimpleDateFormat myDateFormat = new SimpleDateFormat(MY_PATTERN); 

    then you won't have to create it all the time.