-2

我正在尝试在此代码中检索和显示哈希映射值,但我希望输出是单独的值...我该怎么做

代码:

import java.util.*;
import java.io.*;
import java.lang.*;

public class TaskList
{   

    private static HashMap<Integer, Object[]> dataz = new HashMap<Integer,Object[]>();
    private static  HashMap<Integer, Object[]> screen_dataz = new HashMap<Integer,Object[]>();
    public final static Object[][] longValues = {{"10", "kstc-proc", "10.10.","5","O"},{"11", "proc-lvk1", "12.1.2.","4","O"},{"13", "trng-lvk1", "4.6.1.","3","O"}};
    private static String sl,pid,tid,mval,status;

    public static void main(String args[])
    {
        addTask();
    }

    public static void addTask()
    {  
        for (int k=0; k<longValues.length; k++)
        {
        screen_dataz.put(k,longValues[k]);
        }
        Set mapSet = (Set) screen_dataz.entrySet();
        Iterator mapIterator = mapSet.iterator();
        while (mapIterator.hasNext()) 
 {
     Map.Entry mapEntry = (Map.Entry) mapIterator.next();
     Integer keyValue = (Integer) mapEntry.getKey();
     Object[] value = (Object[]) mapEntry.getValue();
     //iterate over the array and print each value
     for (int i=0; i<value.length; i++) {
         System.out.print(value[i] + " ");
     }
     System.out.println();
 }
    }
} 

现在我得到这样的输出:

输出:

10 kstc-proc 10.10. 5 O 
11 proc-lvk1 12.1.2. 4 O 
13 trng-lvk1 4.6.1. 3 O 

我想要一组这样的输出。说第三行输出

输出:

13
trng-lvk1
4.6.1.
3
O
4

2 回答 2

5

说真的,这是你的问题?我可能不应该回答这个问题。

代替

System.out.print(value[i] + " ");

System.out.println(value[i] + " ");
                ^^
于 2013-06-27T09:08:32.603 回答
1

尝试像这样更新您的 for 循环:

   for (int i=0; i<value.length; i++) {
         String arr[] = (String[])values[i];
         for(int k = 0 ; k < arr.length; k++) {
            System.out.println(arr[k]);
         }

     }
于 2013-06-27T09:09:26.157 回答