ArrayListInteger list = new ArrayListInteger();
站在用戶的角度思考問題,與客戶深入溝通,找到漾濞網(wǎng)站設(shè)計與漾濞網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名申請、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋漾濞地區(qū)。
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));
}
package com.zz;
import java.util.ArrayList;
import java.util.List;
public class Test
{
public static void main(String[] args)
{
ListString list1 = new ArrayListString();
ListString list2 = new ArrayListString();
list1.add("a");
list1.add("b");
list1.add("c");
list1.add("d");
list1.add("e");
for (String s : list1)
{
list2.add(s.toUpperCase());
}
list1.clear();
list1 = list2;
System.out.println(list1.toString());
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
private String[] arr1;
private String[] arr2;
public Test(){
//數(shù)組長度可以隨意改,但必須保證兩個數(shù)組長度一樣
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();
}
}
/**
* 獲取組合后的數(shù)組表單
* @return
*/
private ListString[] getcombineList(){
ListString[] list = new ArrayListString[]();
combineArray(list, arr1, arr2);
combineArray(list, arr2, arr1);
return list;
}
/**
* 遍歷數(shù)組str1,并將其復制到新的數(shù)組,再將str2中索引值與str1中索引值
* 相同的元素放入新的數(shù)組,然后將新的數(shù)組放入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);
}
}
/**
* 將數(shù)組每一個元素組合成字符串
* @param str 字符串數(shù)組
* @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集合中的contain方法用來判斷是否存在某個元素,編寫的代碼如下:
import?java.util.HashSet;
class?Dog{
String?color;
public?Dog(String?s){
color?=?s;
}
}
public?class?SetAndHashCode?{
public?static?void?main(String[]?args)?{
HashSetDog?dogSet?=?new?HashSetDog();//新建一個set集合
dogSet.add(new?Dog("white"));//添加元素
dogSet.add(new?Dog("white"));
System.out.println("We?have?"?+?dogSet.size()?+?"?white?dogs!");
if(dogSet.contains(new?Dog("white"))){//contain判斷是否存在某個元素
System.out.println("We?have?a?white?dog!");
}else{
System.out.println("No?white?dog!");
}
}
}