真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java集合形象代碼 java 集合類型

java幫忙寫寫,幾種集合的運(yùn)用,我是菜鳥!

ArrayListInteger list = new ArrayListInteger();

創(chuàng)新互聯(lián)建站自2013年起,先為喀喇沁等服務(wù)建站,喀喇沁等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為喀喇沁企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

list.addAll(Arrays.asList(17,48,93,75,85));

Integer max = Collections.max(list);

Integer sum = 0;

for (Integer i : list) {

sum += i;

}

//最大值max,和sum

HashSetString set = new HashSetString();

set.addAll(Arrays.asList("a","b","c","d","e"));

for (String s : set) {

//輸出Set

System.out.print(s);

System.out.print("\t");

}

HashMapString, String map = new HashMapString, String();

//輸入Map

Scanner input = new Scanner(System.in);

for (int i = 0; i 5; i++) {

System.out.print("鍵:");

String k = input.nextLine();

System.out.print("值:");

String v = input.nextLine();

map.put(k, v);

}

map.put("a", "a");

map.put("b", "b");

map.put("c", "c");

map.put("d", "d");

map.put("e", "e");

Set keyset = map.keySet();//Map所有鍵

Collection values = map.values();//Map所有值

//輸出Map

for (Object obj : keyset) {

System.out.print(obj);

System.out.println(":");

System.out.println(map.get(obj));

}

各位大神高分求一個JAVA集合問題,請給出詳細(xì)的代碼

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Map.Entry;

import java.util.Set;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class Test {

public static String str = "[{TIME=2006-06, PRICE=246.91388889, AccountMethod=7, BW_VALUE=88888}, {TIME=2006-07, PRICE=305611.11111111, AccountMethod=1, BW_VALUE=7070120}, {TIME=2006-08, PRICE=246.91388889, AccountMethod=1, BW_VALUE=88888}, {TIME=2006-08, PRICE=246.91388889, AccountMethod=7, BW_VALUE=7777}]";

public static ListDemo demos = new ArrayListDemo();

public static MapString, Demo maps = new HashMapString, Demo();

public static Pattern p = Pattern點(diǎn)抗 pile("\\{.*?\\}");

public static Pattern p_time = Pattern點(diǎn)抗 pile("TIME=.*?,");

public static Pattern p_price = Pattern點(diǎn)抗 pile("PRICE=.*?,");

public static Pattern p_account = Pattern點(diǎn)抗 pile("AccountMethod=.*?,");

public static Pattern p_value = Pattern點(diǎn)抗 pile("BW_VALUE=.*?\\}");

public static void main(String[] args) {

Matcher m = p.matcher(str);

while (m.find()) {

Demo demo = null;

String s = m.group();

String t = null;

Matcher m2 = null;

m2 = p_time.matcher(s);

if (m2.find()) {

t = m2.group();

t = t.substring(5, t.length() - 1);

if (maps.containsKey(t)) {

demo = maps.get(t);

m2 = p_price.matcher(s);

if (m2.find()) {

String p = m2.group();

demo.setPRICE(demo.getPRICE() + "+"

+ p.substring(6, p.length() - 1));

}

m2 = p_account.matcher(s);

if (m2.find()) {

String a = m2.group();

a = a.substring(14, a.length() - 1);

if (a.equals("7")) {

m2 = p_value.matcher(s);

if (m2.find()) {

String v = m2.group();

v = v.substring(9, v.length() - 1);

demo.setFree(Double.parseDouble(v)

+ demo.getFree());

}

} else {

m2 = p_value.matcher(s);

if (m2.find()) {

String v = m2.group();

v = v.substring(9, v.length() - 1);

demo.setCharge(Double.parseDouble(v)

+ demo.getCharge());

}

}

}

} else {

demo = new Demo();

demo.setTIME(t);

m2 = p_price.matcher(s);

if (m2.find()) {

String p = m2.group();

demo.setPRICE(p.substring(6, p.length() - 1));

}

m2 = p_account.matcher(s);

if (m2.find()) {

String a = m2.group();

a = a.substring(14, a.length() - 1);

if (a.equals("7")) {

m2 = p_value.matcher(s);

if (m2.find()) {

String v = m2.group();

v = v.substring(9, v.length() - 1);

demo.setFree(Double.parseDouble(v));

}

} else {

m2 = p_value.matcher(s);

if (m2.find()) {

String v = m2.group();

v = v.substring(9, v.length() - 1);

demo.setCharge(Double.parseDouble(v));

}

}

}

}

}

maps.put(t, demo);

}

System.out.println(getResult());

}

public static String getResult() {

StringBuffer sb = new StringBuffer();

sb.append("[");

IteratorString iter = maps.keySet().iterator();

while (iter.hasNext()) {

String key = iter.next();

Demo demo = maps.get(key);

String temp = null;

if (demo.getFree() != 0) {

if (demo.getCharge() != 0) {

temp = "{TIME=" + demo.getTIME() + ",PRICE="

+ demo.getPRICE() + ",charge=" + demo.getCharge()

+ ",free=" + demo.getFree() + "}";

} else {

temp = "{TIME=" + demo.getTIME() + ",PRICE="

+ demo.getPRICE() + ",free=" + demo.getFree() + "}";

}

} else {

if (demo.getCharge() != 0) {

temp = "{TIME=" + demo.getTIME() + ",PRICE="

+ demo.getPRICE() + ",charge=" + demo.getCharge()

+ "}";

} else {

temp = "{TIME=" + demo.getTIME() + ",PRICE="

+ demo.getPRICE() + "}";

}

}

sb.append(temp + ",");

}

sb.deleteCharAt(sb.length() - 1);

sb.append("]");

return sb.toString();

}

}

其中的Demo就是一個javabean。

java 代碼 用Collections 里的方法 用集合的方式 表現(xiàn) 數(shù)字的快速排列 JDK1.6

package com.test.jdbc;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

/**

* 根據(jù) order字段對 User 排序

*/

public class User implements ComparableUser {

private String name;

private Integer order;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Integer getOrder() {

return order;

}

public void setOrder(Integer order) {

this.order = order;

}

public int compareTo(User arg0) {

return this.getOrder()點(diǎn)抗 pareTo(arg0.getOrder());

}

public static void main(String[]args){

User user1 = new User();

user1.setName("a");

user1.setOrder(1);

User user2 = new User();

user2.setName("b");

user2.setOrder(2);

ListUser list = new ArrayListUser();

//此處先add user2再add user1

list.add(user2);

list.add(user1);

Collections.sort(list);

for(User u:list){

System.out.println(u.getName());

}

}

}


當(dāng)前標(biāo)題:java集合形象代碼 java 集合類型
URL地址:http://weahome.cn/article/ddegphg.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部