java的集合代码 java集合怎么写

将两个数组 排列组合到一个数组集合 求java 代码import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
private String[] arr1;
private String[] arr2;
public Test(){
//数组长度可以随意改java的集合代码,但必须保证两个数组长度一样
arr1 = new String[3];
arr2 = new String[3];
initArray();
}
private void initArray(){
Scanner scanner = new Scanner(System.in);
for(int i=0;iarr1.length;i){
arr1[i] = scanner.next();
}
for(int i=0;iarr2.length;i){
arr2[i] = scanner.next();
}
}
/**
* 获取组合后java的集合代码的数组表单
* @return
*/
private ListString[] getcombineList(){
ListString[] list = new ArrayListString[]();
combineArray(list, arr1, arr2);
combineArray(list, arr2, arr1);
return list;
}
/**
* 遍历数组str1java的集合代码,并将其复制到新的数组java的集合代码,再将str2中索引值与str1中索引值
* 相同的元素放入新的数组,然后将新的数组放入list中
* @param list
* @param str1
* @param str2
*/
private void combineArray(ListString[] list,String[] str1, String[] str2){
for(int i=0; istr1.length; i){
String[] str = new String[str1.length];
for(int j=0; jstr2.length; j){
str[j] = str2[j];
if(i == j)
str[j] = str1[j];
}
System.out.println(getArrayMessage(str));
list.add(str);
}
}
/**
* 将数组每一个元素组合成字符串
* @param str 字符串数组
* @return 组合字符串
*/
private String getArrayMessage(String[] str){
StringBuffer buffer = new StringBuffer();
for(int i=0; istr.length; i){
if(i == str.length-1)
buffer.append(str[i]);
else
buffer.append(str[i]).append(",");
}
return buffer.toString();
}
public static void main(String[] argv){
Test test = new Test();
test.getcombineList();
}
}
各位大神高分求一个JAVA集合问题,请给出详细的代码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=https://www.04ip.com/post/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.compile("\\{.*?\\}");
public static Pattern p_time = Pattern.compile("TIME=.*?,");
public static Pattern p_price = Pattern.compile("PRICE=.*?,");
public static Pattern p_account = Pattern.compile("AccountMethod=.*?,");
public static Pattern p_value = https://www.04ip.com/post/Pattern.compile("BW_VALUE=https://www.04ip.com/post/.*?\\}");
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();
}
}
其中java的集合代码的Demo就是一个javabean 。
Java的集合怎么添加数据先添加集合java的集合代码的数据java的集合代码,list.add("");
对于集合类的操作的java代码实现的方法//我用集合框架的老大跟子类ArrayList给你写个例子
import java.util.*;
public class CollectionDemo{
public static void main(String[] args){
Collection c = new ArrayList();
//增加
c.add("Java01");
c.add("Java02");
//删除0角标的值
c.remove(0);
//排序为了方便,我把集合框架转成了String[]数组
String[] arr = new String[c.size()];
arr = c.toArray();
Arrays.sort(arr);
//最大值
System.out.println(arr[arr.length-1]);
//因为我是String字符串集合值,没办法比较平均值,可以更改为Interger
}
}
【java的集合代码 java集合怎么写】关于java的集合代码和java集合怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读