怎么new一个对象数组java

首先我们需要创建一个class:

class Student{ String name; double score; String num; Student(String n,double s,String m){ name=n; s=score; num=m; } public static void printInfo(){ System.out.println(num+","+name+","+score); } }

接下来我们对此类进行数组的创建:

//1 Student stu[];<span > </span>//声明数组。 stu=new Student [3];<span > </span>//创建数组,这里是创建的一个引用的数组,每一个引用并没有确切的地址。 for(int i=0;i<3;i++){<span > </span>//为数组创建对象,也就是说为创建的引用关联到确切的地址。 stu[i]=new Student(); } //2 Student stu[]=new Student [3]; for(int i=0;i<3;i++){ stu[i]=new Student(); } //3 Student stu[]=new Student{new Student(sjl,87,01),new Student(ljs,98,02),new Student(lls,92,03)};

java中怎么将由数字组成的字符串转化为数组

我觉得最直接简单的办法,string str="abcdef";List list=new ArrayList();

for(int i=0;i<str.length();i++){

char c=str.charAt(i);

list.add(c);

}

然后就可以对数组list自由操作了。

json数组格式

示例说明

JSON 格式表示数组

保存名字的数组: ["张三","李四","王五"]

保存雇员的信息: ["smith",1001,"clerck",7788,2000.00,200.0]

[

  ["smith",1001,"clerck",7788,2000.00,200.0]

  ["smith",1001,"clerck",7788,2000.00,200.0]

  ["smith",1001,"clerck",7788,2000.00,200.0]

]

[

  {"name":"smith","empno":1001,"job":"clerck","sal":9000.00,"comm":5000.00},

  {"name":"smith","empno":1001,"job":"clerck","sal":9000.00,"comm":5000.00},

  {"name":"smith","empno":1001,"job":"clerck","sal":9000.00,"comm":5000.00},

]

Demo: 对象数组

在一个数组保存多个 json 对象 (在一个数组中保存多个对象)

[

  {

字符串数组java,字符串数组怎么定义

    "title":"Java 开发",

    "edition":3,

    "author":["smith","张三","李四"]

  },

  {

    "title":"Web 开发",

    "edition":3,

    "author":["Allen","王五","赵六"]

  }

]

二维数组保存

[

  ["Java 开发",3,["smith","张三","李四"]],

  ["Web 开发",3["Allen","王五","赵六"]]

]