当前位置: 编程技术>移动开发
本页文章导读:
▪汉语言姓名排序 中文姓名排序
在android中,我们经常要用到HashMap,经常用list存放HashMap,我们对List中的元素进行排序的时候,就要用到构造器了,下面具体用列子说说:
假如在main方法中有:
public List<H.........
▪ ArrayList遍历的四种方法 ArrayList遍历的4种方法
package com.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ArrayListDemo {
public static void main(String args[]){
List<String> list = new ArrayList&l.........
▪ Sinatra:Base#get Sinatra::Base#get
1107 # Defining a `GET` handler also automatically defines1108 # a `HEAD` handler.1109 def get(path, opts={}, &block) 1110 conditions = @conditions.dup 1111 .........
[1]汉语言姓名排序
来源: 互联网 发布时间: 2014-02-18
中文姓名排序
在android中,我们经常要用到HashMap,经常用list存放HashMap,我们对List中的元素进行排序的时候,就要用到构造器了,下面具体用列子说说:
假如在main方法中有:
public List<HashMap<String, Object>> listitem; listitem.add(new HashMap("name","one")); listitem.add(new HashMap("name","张三")); listitem.add(new HashMap("name","李四")); listitem.add(new HashMap("name","王五")); listitem.add(new HashMap("name","two")); Comparent comparent = new Comparent(); Collections.sort(listitem, comparent);
其中在Comparent.java文件中定义方法如下:
import java.text.Collator; import java.util.Comparator; import java.util.HashMap; import java.util.Locale; public class Comparent implements Comparator<Object> { @SuppressWarnings("unchecked") @Override public int compare(Object arg0, Object arg1) { HashMap<String, Object> name1 = (HashMap<String, Object>)arg0; HashMap<String, Object> name2 = (HashMap<String, Object>)arg1; Collator ca = Collator.getInstance(Locale.CHINA); int flags = 0; if (ca.compare((String) name1.get("name"), (String)name2.get("name")) < 0) { flags = -1; } else if(ca.compare((String) name1.get("name"), (String)name2.get("name")) > 0) { flags = 1; } else { flags = 0; } return flags; } }
[2] ArrayList遍历的四种方法
来源: 互联网 发布时间: 2014-02-18
ArrayList遍历的4种方法
package com.test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ArrayListDemo { public static void main(String args[]){ List<String> list = new ArrayList<String>(); list.add("luojiahui"); list.add("luojiafeng"); //方法1 Iterator it1 = list.iterator(); while(it1.hasNext()){ System.out.println(it1.next()); } //方法2 for(Iterator it2 = list.iterator();it2.hasNext();){ System.out.println(it2.next()); } //方法3 for(String tmp:list){ System.out.println(tmp); } //方法4 for(int i = 0;i < list.size(); i ++){ System.out.println(list.get(i)); } } }
[3] Sinatra:Base#get
来源: 互联网 发布时间: 2014-02-18
Sinatra::Base#get
1107 # Defining a `GET` handler also automatically defines
1108 # a `HEAD` handler.
1109 def get(path, opts={}, &block)
1110 conditions = @conditions.dup
1111 route('GET', path, opts, &block)
1112
1113 @conditions = conditions
1114 route('HEAD', path, opts, &block)
1115 end
1107 # Defining a `GET` handler also automatically defines
1108 # a `HEAD` handler.
1109 def get(path, opts={}, &block)
1110 conditions = @conditions.dup
1111 route('GET', path, opts, &block)
1112
1113 @conditions = conditions
1114 route('HEAD', path, opts, &block)
1115 end
最新技术文章: