How to compare string values of CharSequence[]?

百般思念 提交于 2019-12-13 03:59:48

问题


I have the following CharSequence defined:

final CharSequence[] videoQualities = {"any", "medium", "high", "hd"};

I am getting two string values: availableQuality and requestedQuality. Both can contain values from the CharSequence above only.

How can I check if availableQuality more or equal to requestedQuality?


回答1:


Try using an ArrayList instead of CharSequence[]. You can then use ArrayList.indexOf() to return a numeric index that you can use to compare position in the ArrayList.




回答2:


Enum to rescue.

define videoQualities as enum

public enum VideoQualities { any, medium, high, hd }

VideoQualities availableQuality; VideoQualities requestedQuality;

if (availableQuality.ordinal() >= requestedQuality.ordinal()) { .... }



来源:https://stackoverflow.com/questions/5782638/how-to-compare-string-values-of-charsequence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!