Java陣列操作

2021-08-21 20:04:51 字數 766 閱讀 1007

系統中有乙個表中,人員存放的是多個

並且,存放的不是姓名,而是code,code之間使用逗號分隔

頁面,需要顯示所有人員的姓名

把陣列中的code,作為key放在map中,獲取每乙個員工姓名

public string list(pagepage, model model, @requestparam mapparam) else

if (namemap.size() == 0) else else

k = k + 1;

}samplepreparationinfoextlist.get(i).setlabsampleacceptor(opertorname);}}

}setcommondata(model);

page.setresult(samplepreparationinfoextlist);

model.addattribute("page", page);

return

this.viewname("list");

}// 獲取化驗員姓名

public string getopertornamebycode(listpersoninfolist, string opertorcode) }}

return opertorname;}

注意 使用substring擷取string,必須保證這個code的位數,必須是固定的

考慮到效能,只有list在不大的情況下,才可以使用

或者盡量過濾list集合中的資料,減少遍歷次數

Java陣列常用操作

宣告 方式1 推薦,更能表明陣列型別 type 變數名 new type 陣列中元素的個數 比如 int a new int 10 陣列名,也即引用a,指向陣列元素的首位址。方式2 同c語言 type變數名 new type 陣列中元素的個數 如 int a new int 10 方式3 定義時直接...

java中陣列操作

一.計算陣列中最大的值 public static int arraymaxelement int data return max 1,定義乙個max為陣列的0下標,先用for迴圈遍歷出陣列所有的值 2,用if判斷如果data i 大於max那就是最大的值 再用data i 賦給max取到最大值 返...

Java基礎之陣列的操作

陣列的遍歷一般採用for迴圈的方式對陣列依次輸出,在for迴圈的過程中可對輸出格式進行裝飾。首先我們定義乙個陣列 int arr 下面我們寫乙個方法printarr 用於遍歷陣列 public static void printarr int arr 思路 相鄰的兩個元素比較,如果符合條件換位。排序...