1、集合泛型 参数设置两种方式:
public void setData(ArrayList data) { mNavigatorAdapter.setData(data); } publicvoid setData(ArrayList data) { mNavigatorAdapter.setData(data); }
2、map排序
Comparator mComparator = new Comparator() { public int compare(String str1, String str2) { return str1.compareTo(str2); } }; Map sortMap = new TreeMap<>(mComparator); if(params != null){ sortMap.putAll(params); } StringBuilder sb = new StringBuilder(); for (Map.Entry entry : sortMap.entrySet()) { sb.append(entry.getValue()); }
3、单例
publlic class Singleton { private Singleton() {} private static class SingletonLoader { private static final Singleton INSTANCE = new Singleton(); } public static Singleton getInstance() { return SingletonLoader.INSTANCE; }}//这种方式可以给构造函数传参public class Singleton { private volatile static Singleton instance; //声明成 volatile private Singleton (){} public static Singleton getSingleton() { if (instance == null) { synchronized (Singleton.class) { if (instance == null) { instance = new Singleton(); } } } return instance; } }
4、重写equals方法,可以比较两个不同对象的是否相等,可以用于ArrayList排重