What Is Ljava. Lang. String; @

What Is Ljava. Lang. String; @

I have a string array selectCancel with setter and getter methods, which is a checkbox in my form. I am trying to get the checked values and I am getting the above result when I print.

I tried the Arrays.toString() method but it still prints the same.

I then did the following:

String checked = Arrays.toString(Employee.getSelectCancel());

I also tried with the Arrays.asList() and Arrays.copyOf()

So, how do I read this string?

1

6 Answers

The method works if you provide an array. The output of

String[] helloWorld = {"Hello", "World"};
System.out.println(helloWorld);
System.out.println(Arrays.toString(helloWorld));

is

[Ljava.lang.String;@45a877
[Hello, World]

(the number after @ is almost always different)

Please tell us the return type of Employee.getSelectCancel()

Ljava.lang.String;@ is returned where you used string arrays as strings. Employee.getSelectCancel() does not seem to return a String[]

1

According to the Java Virtual Machine Specification (Java SE 8), JVM §4.3.2. Field Descriptors:

FieldType term | Type      | Interpretation
-------------- | --------- | --------------
L ClassName ;  | reference | an instance of class ClassName
[              | reference | one array dimension
...            | ...       | ...

the expression [Ljava.lang.String;@45a877 means this is an array ( [ ) of class java.lang.String ( Ljava.lang.String; ). And @45a877 is the address where the String object is stored in memory.

[ stands for single dimension array
Ljava.lang.String stands for the string class (L followed by class/interface name)

Few Examples:

  1. Class.forName("[D") -> Array of primitive double
  2. Class.forName("[[Ljava.lang.String") -> Two dimensional array of strings.

List of notations:
Element Type : Notation
boolean : Z
byte : B
char : C
class or interface : Lclassname
double : D
float : F
int : I
long : J
short : S

I have the same trouble: I make my own methods: So if I gonna call method like this:

Show("Additional String like this:"+ MyArray);//wrong command

have error! It's must be without "Additional String like this:" just do like this:

Show(AnyArray);//right command

package j;

class J{
public static String [] AnyArray = new String[3];

public static void main(String[] args) {

AnyArray[0]="String_0";
AnyArray[1]="String_1";
AnyArray[2]="String_2";

/******************************************************/
Show(AnyArray); //right
/*****************************************************/
Show("Additional String like this"+AnyArray);//wrong
/****************************************************/
}


public static void Show(String[] MyArray)
{
for(int i=0;i<=MyArray.length-1;i++){
System.out.println("MyArray ["+i+"]: "+MyArray[i]+"");
 }
}



public static void Show(String MyString)
{
System.out.println(MyString);
 }

}

I also met this problem when I've made ListView for android app:

Map<String, Object> m;

for(int i=0; i < dates.length; i++){
    m = new HashMap<String, Object>();
    m.put(ATTR_DATES, dates[i]);
    m.put(ATTR_SQUATS, squats[i]);
    m.put(ATTR_BP, benchpress[i]);
    m.put(ATTR_ROW, row[i]);
    data.add(m);
}

The problem was that I've forgotten to use the [i] index inside the loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.