Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3665034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:42:45+00:00 2026-05-19T01:42:45+00:00

public class TestClass{ private String divisions[] ={}; public void doAction(){ Collection testArray = new

  • 0
public class TestClass{


private String divisions[] ={};


public void doAction(){

 Collection testArray = new ArrayList();
 // put testArray will data

  divisions = (String [] )  testArray.toArray(division);    //should i use this
 divisions = (String [] )  testArray.toArray(new String [] {});   //should i use this?

}

}

if i use case 1, and i call doaction multiple time, the division, something will show wrong records
if i use case2, divisions will always show the correct records. is my assumption should use case 2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:42:46+00:00Added an answer on May 19, 2026 at 1:42 am

    Yes, in case 1 you could have a problem with extra items on the end of division. Example: the first time you called doAction and division was set to a certain length then if the next time you called it, it needed less space, there would be extra items that did not get overwritten in the array.

    However, case 2 is not all that useful because if the array you pass in (which has a length of zero in your example) is not large enough, ArrayList will just create a new array anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this: public class TestClass { private String a; private String b; public TestClass()
My jpa looks like below public class TESTClass implements Serializable { ... private String
Given the following class: class TestClass { public void SetValue(int value) { Value =
public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
Okay, let's say we have a class defined like public class TestClass { private
Say I have a class: public class TestClass { public String Str1; public String
I recently implemented a class like: class TestClass : IDisposable { RegistryKey m_key; public
public class MyClass { public int Age; public int ID; } public void MyMethod()
public class Address { public string ZipCode {get; set;} } public class Customer {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.