ArrayListInteger list = new ArrayListInteger();
站在用户的角度思考问题,与客户深入沟通,找到漾濞网站设计与漾濞网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、网站设计、企业官网、英文网站、手机端网站、网站推广、域名申请、网络空间、企业邮箱。业务覆盖漾濞地区。
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(){
//数组长度可以随意改,但必须保证两个数组长度一样
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();
}
}
/**
* 获取组合后的数组表单
* @return
*/
private ListString[] getcombineList(){
ListString[] list = new ArrayListString[]();
combineArray(list, arr1, arr2);
combineArray(list, arr2, arr1);
return list;
}
/**
* 遍历数组str1,并将其复制到新的数组,再将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集合中的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!");
}
}
}