Link to home
Start Free TrialLog in
Avatar of epifanio67
epifanio67

asked on

Java: why can I not add values to my Object[ ]?

Hello Experts,

Why can I not add values to my Obj [ ] ?

public static void main(String args[]) {

	Pattern p = Pattern.compile("Sip\\w*");

	String file = "message SipRoute test in SipUser " + "\n"
		+ "receipt SipCall at time SipUpdate " + "\n"
		+ "message SipReg during SipDiv " + "\n";

	ArrayList<String> list = new ArrayList<String>();
	Object obj[] = null;

    	Matcher matcher = p.matcher(file);
    	while(matcher.find() == true){
    		list.add(matcher.group());
		obj = new Object[]{matcher.group()};
	}

    	//prints arraylist ok
	for (int x = 0; x < list.size(); x++) {
		System.out.println("myArray: " + list.get(x));
	}

	//fails to add to Obj array - why?
	for (int x = 0; x < obj.length; x++) {
		System.out.println("obj: " + obj[x]);
	}
			
  }

Open in new window


In advance, thank you for your help...

Regards,
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of epifanio67
epifanio67

ASKER

I see what you mean....
Thx for your help...
Regards,
:)