저는 Java를 처음 사용합니다. 어떻게 문자열 데이터를 객체 "myData
"에 추가하고 메인에 그 내용을 출력합니까?Java : 객체에 데이터를 어떻게 추가합니까?
@Override
public String toString() {
return "myData{" +
"fullName=" + Arrays.toString(fullName) +
", skype='" + skype + '\'' +
", github='" + github + '\'' +
", myData=" + myData +
'}';
}
:이 같은 예를 들어, 방법 toString()
을 무시할 수있는 내용을 인쇄하려면
public static void main(String[] args) {
myData myData = new myData(myArray, "skype", "github");
...
}
:
public class myData {
static String[] myArray = new String[] { "Mimi Rudolph", "minirudolph" };
public static String[] cutName(String string) {
return string.split(" ");
}
String[] fullName = cutName(myArray[0]);
String skype = myArray[1];
String github = null;
Object myData = new Object();
public myData(String[] fullName, String skype, String github) {
this.fullName = fullName;
this.skype = skype;
this.github = github;
}
public static void main(String[] args) {
Object myData = new Object();
}
}
고마워요! 그게 내가 원하는거야! :) – Tai