CIT590 From Python to Java

A python list with square brackets s u e t or l t e s

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: on list, with square brackets: s u e t [ ]or l t e s i [ ] tdns0 etrj. Declaring an array does not creat e one. The declaration tells how many dimensions the array has, but never its size: for example, c a [ hr] [ l t e s To create one, use the word n w then its type and size; n w c a [ ] 5 . etr. e, e hr5 Python has list literals: [ , 2 3 4 . Java has two different syntaxes for array literals: 1 ,,] In a declaration (only): i t ] n m e s = { , 2 3 4 ; n[ ubr 1 ,,} Other places: n w i t ] { , 2 3 4 e n[ 1 , , } Java has no equivalent to Python's l s [ : ]notation. itij Python list → Java Ar r ayList An A r y i tacts more like a Python list, but uses only object syntax. There are no literals. raLs AryitSrn>lnugs=nwAryitSrn>) raLs<tig agae e raLs<tig(; lnugsad"yhn) / apn t ls agae.d(Pto"; / ped o it Srn odagae=lnugsgt0; tig lLnug agae.e() lnugsst0 "aa) agae.e(, Jv"; Some additional methods: b o e n i E p y ) b o e n c n a n ( b e t , i t s z ( , t p r m v ( n e ) ola smt(, ola otisojc) n ie) ye eoeidx. Python tuples → No Java equivalent Python set → Java HashSet matuszek/cit590- 2013/Pag es/python- to- java.html 2/6 3/13/13 CIT590 Fr om Python to Java A H s S tis like a Python set, but uses only object syntax. There are no literals. Declaration and creation look like: ahe HsSttp>vral =nwHsSttp>) ahe<ye aibe e ahe<ye(; Some methods: b o e n a d o j c ) b o e n r m v ( b e t , b o e n i E p y ) ola d(bet, ola eoeojc) ola smt(, b o e n c n a n ( b e t , b o e n a d l ( o l c i n (union), b o e n r t i A l c l e t o ) ola otisojc) ola dAlcleto) ola eanl(olcin (intersection), b o e n r m v A l c l e t o ) (set difference), b o e n c n a n A l c l e t o )(subset). ola eoel(olcin ola otisl(olcin A H s S tis one kind of collection. Operations that may change the set return t u if the set was changed, f l eotherwise. ahe re as Python dictionar y → Java HashM ap A H s M pis like a Python dictionary, but uses only o...
View Full Document

This document was uploaded on 02/02/2014.

Ask a homework question - tutors are online