-3

Before check if it's duplicate, I just checked these questions: How do I convert [[Ljava.lang.String;@7defb4fb] to a String and Why does println(array) have strange output? ("[Ljava.lang.String;@3e25a5")

Well, when my action method it's called on debug mode, I have something like this:

RenderBandejasForm bandejaForm = (RenderBandejasForm) form; String [] ts = bandejaForm.getTareasSeleccionadas();

The problem comes when I try to iterate this, ts value is something like [Ljava.lang.String;@64c064c, so, how I'm suppose to loop this?

I tried to get something in outputs like:

System.out.println(Arrays.toString(ts));

getting the same weird output: [Ljava.lang.Long;@64c064c

I tried to loop through it too:

    for (String temp : ts){
         String test1 = temp;
    }

the string test1 shows something different [Ljava.lang.Long;@differentNumbers

I think that I'm making calls to the memory object, and not calling the array right?

edited:

The method getTareasSeleccionadas() should print a String array, something like this: [66344,66345,66553] but I always get that output [Ljava.lang.Long;@64c064c

edited 2: Here is all the code of the function that I have:

/**
 * Elimina una o más tareas.
 */
public ActionForward eliminarTareas(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {

    RenderBandejasForm bandejaForm = (RenderBandejasForm) form;
    String [] ts = bandejaForm.getTareasSeleccionadas();

    //here I start my tests

    for (String temp : ts){
         String test1 = temp;
    }

    String test2 = Arrays.deepToString(ts);
    String test3 = Arrays.toString(ts);

    //Here I finish'em

    return this.bandeja(mapping, bandejaForm, request, response);
}
Community
  • 1
  • 1
jvillegas
  • 71
  • 1
  • 2
  • 11
  • Why the questions you checked do not answer your question? What exactly is the issue? – Tunaki May 19 '16 at 11:11
  • 2
    How are we supposed to know what `getTareasSeleccionadas` returns? Please [edit] your question and add a [mcve]. – RealSkeptic May 19 '16 at 11:16
  • did you by any chance name a class `String` in your project? – SomeJavaGuy May 19 '16 at 11:17
  • No, I don't Kevin. – jvillegas May 19 '16 at 11:19
  • 1
    I am very tempted to vote to close your question as duplicate because questions pointed by you already contain answer you are looking for, but you just don't know it yet. If by looping your `String[]` and printing its content you are seeing something like `[Ljava.lang.Long;@64c064c` then this means you actually put that value in that array. So somewhere in your code you forgot to use `Arrays.toString(yourArray)` but you invoked `yourArray.toString()` (explicitly or implicitly). Either show us your actual code which will let us reproduce your problem or be ready to see this question closed. – Pshemo May 19 '16 at 11:47
  • I just edited my code, @Pshemo – jvillegas May 19 '16 at 12:02
  • 1
    OK, I'm going to vote to close this question, because you have not provided the information required to help you. That is, the code of `getTareasSeleccionadas`, and anything else it depends upon, which is not a standard JDK type or a well-known library. – RealSkeptic May 19 '16 at 12:38

2 Answers2

1

This will print what is in the array as strings.

for(String s : ts) {
    System.out.println(s);
}

If that prints addresses (like Ljava.lang.Long@xxx) then that is what is actually in that string. So you might want to check what is inserted into your array.

Edit: Seeing you are entering numbers into it but getting the addresses. Try entering them like array[index] = ""+longValue; Or Long.toString(longValue)

Guus
  • 399
  • 2
  • 15
  • I just loop this before ask my question... There is an example of it in my question. and yeah, I get Ljava.Lang.Long@xxxxxx again, and I don't know what to do next, what can I do? – jvillegas May 19 '16 at 11:26
  • Then your function bandejaForm.getTareasSeleccionadas() returns an array of exactly that content. The error is most likely in the function bandejaForm.getTareasSeleccionadas(). – J Fabian Meier May 19 '16 at 11:44
  • Probably a conversion error from Long to String in bandejaForm.getTareasSeleccionadas(). – J Fabian Meier May 19 '16 at 11:48
0

The user Pshemo ask me to check my code again, cause maybe I forgot to use Arrays.toString() on the correct place, well, here it is:

public ActionForward confirmEliminarTareas(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {

    RenderBandejasForm bandejaForm = (RenderBandejasForm) form;

    request.setAttribute(Constants.TAREAS, 
        Arrays.toString(bandejaForm.getTareasSeleccionadas()));        
    request.setAttribute(Constants.TIPO_BANDEJA,
            bandejaForm.getTipoBandeja());
    request.setAttribute(Constants.TIPO_TAREA, bandejaForm.getTipoTarea());

    return mapping.findForward("confirmEliminarTareas");
}

I focus myself into elimnarTareas, and I forgot my other class, when I debug eliminarTareas, now I get the numbers on array format, something like this: [66348, 65587, 65474, 65382]

jvillegas
  • 71
  • 1
  • 2
  • 11