LoginSignup
4
4

More than 5 years have passed since last update.

ProcessingでLinkedListを使う

Last updated at Posted at 2014-06-22

概要

Processingでテキストエリアを自作しようとしたとき、行の管理(指定行の挿入や削除)をするために順序ありのリスト(LinkedList)が必要となった。
自分の思い込みでProcessingではLinkedListは使えないもんだと思っていたんですが、importすれば普通に使えたので、その方法について。

参考

『コレクション(LinkedList)』(JavaDrive)
http://www.javadrive.jp/start/linkedlist/

手順

LinkedListをimportし、newする。

processing
import java.util.LinkedList;

LinkedList<String> lList = new LinkedList<String>();

要素の追加や削除は、要素番号を指定して行います。

processing
lList.set(5,"hello");  // 5番目の要素を追加
lList.remove(5);      // 5番目の要素を削除

要素を追加・削除すると、それまでの要素番号は更新されます。

まとめ

ProcessingではLinkedListはあまり使われないのか、見たことがなかった。たしかにArrayList使うことのほうが多い。順番を持った最大数の不定なものを作るときに使えるかなと思います。(具体的な例が思いつきませんが…)

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4