導航:首頁 > 編程語言 > java如何讀數組

java如何讀數組

發布時間:2023-09-02 19:39:39

『壹』 js 數組 在java中怎麼讀取 急啊!

javascript是前台的腳本語言、java不能直接讀取、你可以將js的數組以一個特殊符號內分割組成一個字元串容傳到後台在用java的split方法轉換成數組!
比如:
js code: var arr = {'a','b','c'}; => var ss = 「a&b&c」;
java code:String ss = "a&b&c";String[] arr = ss.split('&');

『貳』 java高手請進,我有一個map對象,用來存儲一個數組,如何讀取這個數組呢

public class Solve {

public static void main(String[] args) throws Exception {
int []i = {1,2,3};
HashMap<String, int[]> map = new HashMap<String, int[]>();
map.put("array",i);
int []thatArray = map.get("array");
for(int n:thatArray){
System.out.println(n);
}
}

}

『叄』 java .。map集合中放了個數組,怎麼把數組讀出來。

List<Integer> aa = (List<Integer>)map.get("a");
for(int j=0; j<aa.size(); j++){
System.out.println(aa.get(j));
}

int[]bb = (int[])map.get("b");
for(int j=0; j<bb.length; j++){
System.out.println(bb[j]);
}

『肆』 Java怎麼讀取Vector中的元素(元素是一個數組)

for(int i =0; i<n; ++i) //n為數組長度
{
if(a[i] == temp) //temp為要查找 的元素
return i; //i為該元素在數組中的位置
}

『伍』 JAVA_如何讀出對象數組

//: ArrayObject.java

import java.io.*;

public class ArrayObject {
public static void main(String[] args) {

String file="obj.array";

int[] arr = new int[]{1,2,3,5,7,9,};

//寫數組
save(arr,file);

//讀對象
Object read = load(file);

//遍歷數組
if(read != null && read instanceof int[]){
//直接將讀取到的對象轉型成 數組
int[] readArr = (int[])read;
System.out.println("arr length: "+readArr.length);
for(int i=0; i<readArr.length; i++)
System.out.print(readArr[i]+" ");
}
}

//保存對象到文件
static void save(Object o,String file){
try{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(o);
oos.flush();
oos.close();
}catch(Exception e){e.printStackTrace();}
}

//從文件讀取對象
static Object load(String file){
try{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
Object o = ois.readObject();
ois.close();
return o;
}catch(Exception e){e.printStackTrace();}
return null;
}
}

閱讀全文

與java如何讀數組相關的資料

熱點內容
電腦編程語言怎麼樣 瀏覽:421
wordpress頁面復制 瀏覽:677
app怎麼改流量范圍 瀏覽:1
手機相片源文件怎麼發微信 瀏覽:538
mac上播放swf文件格式 瀏覽:892
linux中更改文件的群組 瀏覽:373
app使用照相許可權的目的是什麼 瀏覽:315
做網站都需要什麼 瀏覽:671
設置n卡程序設置 瀏覽:901
中山哪些是正規網路教育大學 瀏覽:766
發那科系統編程怎麼寫中文 瀏覽:730
電信光貓要用超級賬戶密碼是什麼 瀏覽:73
冰法神器升級路線 瀏覽:795
汽車上的數據都有哪些 瀏覽:149
ipad怎麼刪除文件夾 瀏覽:649
感謝編程學校該怎麼說 瀏覽:217
怎麼給wps文件加密 瀏覽:528
美國有什麼購物網站 瀏覽:208
靈武品牌網路推廣有哪些 瀏覽:398
vhdl編程實例教程 瀏覽:336

友情鏈接