Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a method

public boolean findANDsetText  (String Description, String ... extra ) {

inside I want to call another method and pass it extras but I want to add new element (Description) to extras.

     object_for_text = getObject(find_arguments,extra);

How can I do that in java? What would the code look like?

I tired to accommodate code from this question but couldn't make it work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

To expand on some of the other answers here, the array copy could be done a bit faster with

String[] newArr = new String[extra.length + 1];
System.arraycopy(extra, 0, newArr, 0, extra.length);
newArr[extra.length] = Description;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...