Questions tagged [append]

To append is to join or add on to the end of something.

Append is an operation usually defined on 1D data structures (e.g., , , , , etc.).
The append operation adds an element to the end of the data structure, consequently, increasing its size by one.

11138 questions
64
votes
7 answers

Append a single character to a string or char array in java?

Is it possible to append a single character to the end of array or string in java. Example: private static void /*methodName*/ () { String character = "a" String otherString = "helen"; //this is where i need help, i would…
CodeLover
  • 977
  • 3
  • 9
  • 14
63
votes
7 answers

Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?

I have a big file I'm reading from, and convert every few lines to an instance of an Object. Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping. This is a file that's around…
Deniz
  • 1,481
  • 3
  • 16
  • 21
63
votes
6 answers

R + combine a list of vectors into a single vector

I have a single list of numeric vector and I want to combine them into one vector. But I am unable to do that. This list can have one element common across the list element. Final vector should not add them twice. Here is an example: >lst `1` [1] 1…
Rachit Agrawal
  • 3,203
  • 10
  • 32
  • 56
62
votes
6 answers

Appending to an ObjectOutputStream

Is it not possible to append to an ObjectOutputStream? I am trying to append to a list of objects. Following snippet is a function that is called whenever a job is finished. FileOutputStream fos = new FileOutputStream …
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
61
votes
5 answers

What is the idiomatic way to prepend to a vector in Clojure?

Prepending to a list is easy: user=> (conj '(:bar :baz) :foo) (:foo :bar :baz) Appending to a vector is easy: user=> (conj [:bar :baz] :foo) [:bar :baz :foo] How do I (idiomatically) prepend to a vector, while getting back a vector? This does not…
0x89
  • 2,940
  • 2
  • 31
  • 30
57
votes
3 answers

Appending two dataframes with same columns, different order

I have two pandas dataframes. noclickDF = DataFrame([[0, 123, 321], [0, 1543, 432]], columns=['click', 'id', 'location']) clickDF = DataFrame([[1, 123, 421], [1, 1543, 436]], columns=['click',…
redrubia
  • 2,256
  • 6
  • 33
  • 47
57
votes
9 answers

jQuery appending an array of elements

For the purpose of this question lets say we need to append() 1000 objects to the body element. You could go about it like this: for(x = 0; x < 1000; x++) { var element = $('
'+x+'
'); $('body').append(element); } This works,…
George Reith
  • 13,132
  • 18
  • 79
  • 148
54
votes
6 answers

jQuery - Appending a div to body, the body is the object?

When I'm adding a div to body, it's returning the body as the object and then whenever I use that - it's obviously using body. Bad. Code:- var holdyDiv = $('body').append('div'); $(holdyDiv).attr('id', 'holdy'); The 'id' of holdy is now being added…
waxical
  • 3,826
  • 8
  • 45
  • 69
54
votes
5 answers

C# Append byte array to existing file

I would like to append a byte array to an already existing file (C:\test.exe). Assume the following byte array: byte[] appendMe = new byte[ 1000 ] ; File.AppendAllBytes(@"C:\test.exe", appendMe); // Something like this - Yes, I know this method…
user725913
54
votes
7 answers

Getting access to a jquery element that was just appended to the DOM

I am simply appending an element that is on the DOM like: $("#div_element").append('test'); Right after I append it I need access to the element I just made in order to bind an click function to it, I…
Greg Alexander
  • 1,192
  • 3
  • 12
  • 25
53
votes
5 answers

jQuery append text

I want to append some simple data in a div like: $('#msg').append('Some text'); In the body, i think i will need to place the the html like.
//show text inside it.
However, I want to add some CSS…
sunjie
  • 555
  • 1
  • 4
  • 5
53
votes
3 answers

List append() in for loop raises exception: 'NoneType' object has no attribute 'append'

In Python, trying to do the most basic append function to a list with a loop: Not sure what I am missing here: a = [] for i in range(5): a = a.append(i) returns: 'NoneType' object has no attribute 'append'
jim jarnac
  • 4,804
  • 11
  • 51
  • 88
52
votes
2 answers

How can I use Go append with two []byte slices or arrays?

I recently tried appending two byte array slices in Go and came across some odd errors. My code is: one:=make([]byte, 2) two:=make([]byte, 2) one[0]=0x00 one[1]=0x01 two[0]=0x02 two[1]=0x03 log.Printf("%X", append(one[:], two[:])) three:=[]byte{0,…
ThePiachu
  • 8,695
  • 17
  • 65
  • 94
52
votes
3 answers

Golang concurrency: how to append to the same slice from different goroutines

I have concurrent goroutines which want to append a (pointer to a) struct to the same slice. How do you write that in Go to make it concurrency-safe? This would be my concurrency-unsafe code, using a wait group: var wg sync.WaitGroup MySlice =…
Daniele B
  • 19,801
  • 29
  • 115
  • 173
52
votes
3 answers

Here we go again: append an element to a list in R

I am not happy with the accepted answer to Append an object to a list in R in amortized constant time? > list1 <- list("foo", pi) > bar <- list("A", "B") How can I append new element bar to list1? Clearly, c() does not work, it flattens bar: >…
user443854
  • 7,096
  • 13
  • 48
  • 63