public class listexample {
public list<string> myval {get;set;}
public string str;
public listexample(){
myval=new list<string>();
myval.add('India');
myval.add('USA');
myval.add('Japan');
myval.add(1,'China');
}
str = myval.get(2);
}
1 Answer
str = myval.get(2);
Should be inside constructor
public class listexample {
public list<string> myval {get;set;}
public string str {get; private set;}
public listexample(){
myval=new list<string>();
myval.add('India');
myval.add('USA');
myval.add('Japan');
myval.add(1,'China');
str = myval.get(2);
}
}
Also since you are using str
in VF page, should be in get set property
public string str {get;set;}
If you are just displaying str
in VF page. Use private set;
to ensure this String should not updated from vf page.
-
Thank you Ratan for the detailed response..thanks very much. Commented Mar 15, 2016 at 7:55