-9

Can anyone tell me what is the difference between String and string in Android?

Tom van Enckevort
  • 4,160
  • 1
  • 23
  • 40
Kannan_SJD
  • 913
  • 1
  • 9
  • 30

4 Answers4

6

String is a class which is present in library java.lang.String, whereas string is an xml file

present in values in android where you will refer id with values in which you will retrieve

in coding.

Shadow
  • 6,746
  • 5
  • 37
  • 86
2

string refers to string(sub class) inside R class in your Project.

String refers to java.lang.String package

Gugan
  • 1,586
  • 1
  • 26
  • 61
2

I believe you are asking about java.lang.String and android.R.string.

String class is defined in package java.lang which is automatically imported to your android project (infact all java project).

string is android.R.string, which is static string's given in xml.

Krishnabhadra
  • 33,632
  • 30
  • 110
  • 164
2

Check out these links

String Documentation

string Documentation

For Example look at the code below

String name = "";
  switch (row.getNameKey()) {
  case keyName1:
    name = getString(R.string.keyName1);
    break;
  case keyName2:
    name = ...
    ...
}

R.string is used to getString from Resources (Strings.xml)...

Vaibs_Cool
  • 5,820
  • 5
  • 24
  • 59